zip: a plurality iterables, from the beginning, one returns a tuple
a = ('a','b','c ','c') b = ('a','b','c','c') ret = zip(a,b) for i in ret: print(i) print(list(zip(a,b))) #打印 ('a', 'a') ('b', 'b') ('c ', 'c') ('c', 'c') [('a', 'a'), ('b', 'b'), ('c ', 'c'), ('c', 'c')]
filter: filter, to filter out ineligible elements, return an iterator object consists of qualified elements.
The receiving two parameters, as a function of a first, a second sequence, each element of the sequence as an argument to a function to judge, then return True or False, and finally returns True elements into the new object
l = [1,2,3,-1,-5,0,51] func = filter(lambda x : x > 0,l) for i in func: print(i) #打印: 1 2 3 51
map: map () function accepts two arguments, a function, a sequence is, in turn a function of the incoming effect to each element of the sequence, and the result as a new object l return, Map () is the iterator .
l = [1,2,3,-1,-5,0,51] func = map(lambda x : x + 1,l) for i in func: print(i) #打印 2 3 4 0 -4 1 52
sorted: sorting, and a list of built-in methods different sort, sorted sort all iterables, is to create a sort of memory, it will not affect the original list
= L [l, 2,3, -1, -5,0,51 ] info_sort = the sorted (L, Key = ABS) Print (info_sort) # Printing: [0, 1, -1, 2, 3, -5 , 51]