>>> def factorial(num):
if num == 1:
return 1
else:
return num * factorial(num-1)
>>> factorial(3)
6
>>> factorial(4)
24
>>> map(factorial, [1, 2, 3, 4, 5, 6, 7, 8])
<map object at 0x000001A1735AEB80>
>>> list(map(factorial, [1, 2, 3, 4, 5, 6, 7, 8]))
[1, 2, 6, 24, 120, 720, 5040, 40320]
>>> tuple(map(factorial, [1, 2, 3, 4, 5, 6, 7, 8]))
(1, 2, 6, 24, 120, 720, 5040, 40320)
>>> for i in map(factorial, [1, 2, 3, 4, 5, 6, 7, 8]):
print(i)
1
2
6
24
120
720
5040
40320
>>> map(lambda x : x ** 3, [i for i in range(10)])
<map object at 0x000001A1735AEAF0>
>>> tuple(map(lambda x : x ** 3, [i for i in range(10)]))
(0, 1, 8, 27, 64, 125, 216, 343, 512, 729)
>>> map(list, zip([1, 2, 3], [4, 5, 6]))
<map object at 0x000001A1735AEAF0>
>>> map(lambda x, y : x+y, range(5), range(5))
<map object at 0x0000019CB88CBDC0>
>>> tuple(map(lambda x, y : x+y, range(5), range(5)))
(0, 2, 4, 6, 8)
>>> tuple(map(lambda x, y, z : x-y+z, range(2), range(3), range(6)))
(0, 1)
>>> tuple(map(lambda x, y, z : x-y+z, range(4), range(3), range(6)))
(0, 1, 2)
>>> list((1, 2, 3))
[1, 2, 3]
>>> tuple(map(list, zip([1, 2, 3], [4, 5, 6]))) # 将元组里面的元组转为列表
([1, 4], [2, 5], [3, 6])
>>> tuple(zip([1, 2, 3], [4, 5, 6]))
((1, 4), (2, 5), (3, 6))