Codes Displayed when doing an "svn stat"
U = Working file was updated
G = Changes on the repository were automatically merged into the working copy
M = Working Copy is modified
C = This file conflicts with the version in the repo
? = This file is not under version control
! = This file is under version control but is missing or incomplete
A = This file will be added to version control after commit
A+ = This file will be moved after commit
D = This file will be deleted after commit
I = This item is being ignored (due to the svn:ignore porperty)
L = This file is locked
X = Item is unversioned, but used by an externals definition
~ = Messed up item (file when it should be dir). resolve by moving and doing "svn up"
http://knaddison.com/technology/svn-status-code-cheat-sheet
Showing posts with label list. Show all posts
Showing posts with label list. Show all posts
Tuesday, May 03, 2011
Friday, October 09, 2009
Python List Operations (map, for comprehensions)
EXAMPLE 1
# Create a list
>>> l = [1,2,3,4,5,6]
# iterate through the list using a for comprehension
>>> [i for i in l]
[1, 2, 3, 4, 5, 6]
# square elements in the list using a for comprehension
>>> [i**2 for i in l]
[1, 4, 9, 16, 25, 36]
# square only even elements in the list using a for comprehension
>>> [i**2 for i in l if i % 2 == 0]
[4, 16, 36]
# iterate through the list using map
>>> map(lambda w: w, l)
[1, 2, 3, 4, 5, 6]
# square each element of the list using map
>>> map(lambda w: w**2, l)
[1, 4, 9, 16, 25, 36]
# or use map to call a separately defined function to# iterate through the list
>>> def squa(x):
...... return x**2
>>> map(squa, l)
[1, 4, 9, 16, 25, 36]
# use map function to call a separately defined function that takes 2 args
>>> l2 = map(lambda w: (w,2),l)
>>> l2
[(1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2)]
>>> def pow(base, expo):
...... return base**expo
>>> map(lambda (x,y): pow(x,y), l2)
[1, 4, 9, 16, 25, 36]
# filter a list
>>> filter(lambda w: w > 2, l)
[3, 4, 5, 6]
EXAMPLE 2
# define a simple class to play with
>>> class A(object):
...... def __init__(self, x):
........ self.x = x
# create simple list of object instances of the class
>>> l = [A(1), A(2), A(3)]
# use a for (list) comprehension to iterate through the list
>>> [i.x for i in l]
[1, 2, 3]
# use a for comprehension to iterate with a condition
>>> [i.x for i in l if i.x > 1]
[2, 3]
# use map to apply a function to every element in the list
>>> map(lambda w: w.x, l)
[1, 2, 3]
>>> map(lambda w: w.x * w.x, l)
[1, 4, 9]
# Create a list
>>> l = [1,2,3,4,5,6]
# iterate through the list using a for comprehension
>>> [i for i in l]
[1, 2, 3, 4, 5, 6]
# square elements in the list using a for comprehension
>>> [i**2 for i in l]
[1, 4, 9, 16, 25, 36]
# square only even elements in the list using a for comprehension
>>> [i**2 for i in l if i % 2 == 0]
[4, 16, 36]
# iterate through the list using map
>>> map(lambda w: w, l)
[1, 2, 3, 4, 5, 6]
# square each element of the list using map
>>> map(lambda w: w**2, l)
[1, 4, 9, 16, 25, 36]
# or use map to call a separately defined function to# iterate through the list
>>> def squa(x):
...... return x**2
>>> map(squa, l)
[1, 4, 9, 16, 25, 36]
# use map function to call a separately defined function that takes 2 args
>>> l2 = map(lambda w: (w,2),l)
>>> l2
[(1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2)]
>>> def pow(base, expo):
...... return base**expo
>>> map(lambda (x,y): pow(x,y), l2)
[1, 4, 9, 16, 25, 36]
# filter a list
>>> filter(lambda w: w > 2, l)
[3, 4, 5, 6]
EXAMPLE 2
# define a simple class to play with
>>> class A(object):
...... def __init__(self, x):
........ self.x = x
# create simple list of object instances of the class
>>> l = [A(1), A(2), A(3)]
# use a for (list) comprehension to iterate through the list
>>> [i.x for i in l]
[1, 2, 3]
# use a for comprehension to iterate with a condition
>>> [i.x for i in l if i.x > 1]
[2, 3]
# use map to apply a function to every element in the list
>>> map(lambda w: w.x, l)
[1, 2, 3]
>>> map(lambda w: w.x * w.x, l)
[1, 4, 9]
EXAMPLE 1
# Create a list
>>> l = [1,2,3,4,5,6]
# iterate through the list using a for comprehension
>>> [i for i in l]
[1, 2, 3, 4, 5, 6]
# square elements in the list using a for comprehension
>>> [i**2 for i in l]
[1, 4, 9, 16, 25, 36]
# square only even elements in the list using a for comprehension
>>> [i**2 for i in l if i % 2 == 0]
[4, 16, 36]
# iterate through the list using map
>>> map(lambda w: w, l)
[1, 2, 3, 4, 5, 6]
# square each element of the list using map
>>> map(lambda w: w**2, l)
[1, 4, 9, 16, 25, 36]
# or use map to call a separately defined function to# iterate through the list
>>> def squa(x):
...... return x**2
>>> map(squa, l)
[1, 4, 9, 16, 25, 36]
# use map function to call a separately defined function that takes 2 args
>>> l2 = map(lambda w: (w,2),l)
>>> l2
[(1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2)]
>>> def pow(base, expo):
...... return base**expo
>>> map(lambda (x,y): pow(x,y), l2)
[1, 4, 9, 16, 25, 36]
# filter a list
>>> filter(lambda w: w > 2, l)
[3, 4, 5, 6]
EXAMPLE 3
# split a list into chunks
>>> map(None, *(iter(range(10)),) * 3)
[(0, 1, 2), (3, 4, 5), (6, 7, 8), (9, None, None)]
http://stackoverflow.com/questions/1335392/iteration-over-list-slices
Tuesday, December 16, 2008
Find Usage
"Grep" through each file in a directory:
ls xargs grep -i 'STRING'
List all directories and subdirectories in a directory
find . -type d
List all files in a directory no recursion
# workaround for "parameter list is too long".
find . \( ! -name . -prune \) -name 'STRING*' -print
find . -maxdepth 1 -name 'STRING*' -print # GNU find only
Remove all files in a directory no recursion
# workaround for "parameter list is too long".
find . \( ! -name . -prune \) -name 'STRING*' -print -exec rm {} \;
Find a file with a given inode and delete it
ls -lai # lists the inodes next to the files
find . -inum 12345 -exec rm {} \; # finds and removes by inode
http://www.faqs.org/qa/qa-1381.html
http://sial.org/howto/shell/
ls xargs grep -i 'STRING'
List all directories and subdirectories in a directory
find . -type d
List all files in a directory no recursion
# workaround for "parameter list is too long".
find . \( ! -name . -prune \) -name 'STRING*' -print
find . -maxdepth 1 -name 'STRING*' -print # GNU find only
Remove all files in a directory no recursion
# workaround for "parameter list is too long".
find . \( ! -name . -prune \) -name 'STRING*' -print -exec rm {} \;
Find a file with a given inode and delete it
ls -lai # lists the inodes next to the files
find . -inum 12345 -exec rm {} \; # finds and removes by inode
http://www.faqs.org/qa/qa-1381.html
http://sial.org/howto/shell/
Subscribe to:
Posts (Atom)