List Review
Append (x) Chase to the end of the chain
Extend (L) append a list equivalent to + =
Insert (I,X) inserts x at position I
Remove (x) deletes an element with a value of X if no exception is thrown
Sort () directly modifies the list to a sorted
Sorted (L) returns the sorted L
GANSO data structures that cannot be modified once initialized are faster than the list
Set (set) unordered, non-repeating set of elements is not guaranteed to be ordered
Dictionary (dict) keyword immutable type such as String integer only contains ganso of immutable objects
About the very powerful dictionary function we can do a lot of things like
def leijia (x, y): a = 0 for i in Xrange (x,y+1): A + = i return adef plus (x, y): return X+ymatruix = { ' + ':p LUs, ' Leijia ': Leijia,}def size (x,oper,y): return Matruix[oper] (x, y) print (Size (1, ' Leijia ', 2))
We can do a switch case mode
#filter
A = [1,2,3,4]
Filter (Lamda x:x%2,a)
[1,3]
#map The return sequence can be passed in multiple sequences for each element of the original sequence called function, but the function also has a corresponding number of parameters
Map (Lambda X,y,z:x+y+z,range (1,3), range (3,5), Range (5,7))
Calculation procedure 1+3+5 = 9 2+4+6=12 results [9,12]
Next we're going to implement
L1 = [1,2,3,4]
Oper = [' + ', '-', ' Leijia ', ' * ']
L2 = [2,44,55,66]
#l1 [0] "oper[0]" l2[0]=? ...
Def plus (x, y): return X+ydef Jian (x, y): return x-ydef Leijia (x, y): a = 0 for i in (x, y): a +=1< C6/>return adef Chengji (x, y): return x*ymy_dict = { ' + ':p LUs, '-': Jian, ' Leijia ': Leijia, ' * ': CHENGJI,}L1 = [1,2,3,4]oper = [' + ', '-', ' Leijia ', ' * ']L2 = [2,44,55,66] #L1 [0] "oper[0]" L2 =? .... res = map (lambda x,y,z:my_dict[y] (x,z), l1,oper,l2) print (list (re
01-python Supplements