map/reduce/filter
map
map(function, sequence)[function(item1), function(item2), function(item3), ...]>>> def square(x):
... return x * x
>>> map(square, [1, 2, 3, 4])
[1, 4, 9, 16]
>>> map(lambda x: x * x, [1, 2, 3, 4]) # 使用 lambda
[1, 4, 9, 16]
>>> map(str, [1, 2, 3, 4])
['1', '2', '3', '4']
>>> map(int, ['1', '2', '3', '4'])
[1, 2, 3, 4]reduce
filter
小结
参考资料
Last updated