1. append(x) = > a[len(a):] = [x],
extend(L) => a[len(a):] = L,
insert(i,x) # before i,
remove(x) # remove x or return error,
pop([i]) # default value is the last element, and return that.
count(x) # count the appearance times
sort()
reverse()
2. as a stack
a.append(),a.pop() => push,pop
3. as a queue
a.append(),a.pop(0)=>push_back,pop_front
4. filter(function,sequence)=> each item call function, if that function return true,then the answer include this item
map(function,sequence)=> each item call function, if that is true then add to the answer linked list
map(None,list1,list2) => make two list to be a couple
reduce(function,sequence,[initial val]) => first two item call this function,and then call the function with returned item and the next item,and to the end, when there is only on item then return itself, if sequence is none then throw a exception except there is a initial value
5. derive list
vec = [2,4,5]
[x*3 for x in vec if x>3]
[[x,x**3] for x in vec]
[(x,x**3) for x in vec] # tuples
[x*y for x in vec1 for y in vec2]
[x+y for x in vec1 for y in vec2]
[vec1[i]*vec2[i] for i in range(len(vec1))]
6. del
del a[0]
del a[2:4] # third and forth item
del a
7. tuples
tuple must be nested and can not be changed like string
empty tuple: empty = (), singleton = 'hello', # comma is needed
inverse operation: t = 233,'dasfd',323 x,y,z = t
8. dictionary
associate memories, associate arrays
key:values
t = {'man':0,'woman':1,'child':2}
t['man'],t.has_key('woman') return true
construct a dictionary use list tuple
dict([(x,x*x) for x in vec])
traverse a dictionary
for k,v in t.items():
print k,v
9. use sequence
for i,v in enumerate(['adfd','dklfj','sdf']):
print i,v
10. two or more sequence
for q,a in zip(questions,answers):
print 'what is your %s, it is %s.' %(q,a)
11. compare operation can pass
a < b == c (a<b && b==c)
not > and > or
A and not B or C(A & !B or C)
string1, string2,string3 = '','abc','def'
non_null = string1 or string2 or string3
12. compare
(1,2,3) < (1,2,4)
[1,2,3] < (1,2,4)
'abc'<'c'<'d'
(1,2,3,4) < (2)
(1,2) < (1,2,-1)
(1,2,3) == (1.0,2.0,3.0)
can compare different types,
list < string < tuple