1.zip函数
zip([iterable1,iterable2,...]) 将可迭代对象中对应的元素打包成一个个元组,然后返回由这些元组组成的列表(如果可迭代对象长度不一,返回列表长度和最短的对象相同)
2.map 函数
map(function,iterable,...) 根据提供的函数对指定序列做映射
3.filter 函数
filter(function,iterable) 根据函数对给定的可迭代对象进行过滤
4.sorted函数
sorted(iterable,key/reverse): 对可迭代对象进行排序(可以指定排序的元素key和排序的函数cmp,也可以指定降序: reverse=True,或者升序: reverse=False 默认是升序)
代码:
# zip函数
zipList = zip([1, 2, 3], ['a', 'b', 'c'], ['A', 'B', 'C'])
zipList = list(zipList)
print(zipList)
print(tupelNew)
# map函数
list1 = [1, 2, 3]
list1New = map(lambda x: x * x, list1)
list1New = list(list1New)
print(list1New)
# filter函数
list2 = [1, 2, 3]
newList = filter(lambda x: x % 2 == 1, list2)
newList = list(newList)
print(newList)
# sorted函数
list3 = sorted([('b', 2), ('a', 1), ('c', 3), ('d', 4)], key=lambda x: x[1])
print(list3)