标签:values lam rom ret itertools 相加 map class tools
1.
import numpy as np a = np.array([1,2,3,4]) b = np.array([7,8,9,10]) s = a + b print(s)
[ 8 10 12 14]
2.
from itertools import product
a = [2, 3, 4, 5]
b = [7, 8, 9]
ret2 = [i+j for i, j in product(a, b)]
print(sorted(set(ret2)))
"""
[9, 10, 11, 12, 13, 14]
"""
3.
a = [2, 3, 4, 5]
b = [7, 8, 9]
ret = list(set([i + j for i in a for j in b]))
print(ret)
"""
[9, 10, 11, 12, 13, 14]
"""
4.
a = [2, 3, 4, 5]
b = [6,7, 8,9]
ret2 = [i+j for i, j in zip(a, b)]
print(ret2)
"""
[8, 10, 12, 14]
"""
a = [2, 3, 4, 5]
b = [6,7, 8]
ret2 = [i+j for i, j in zip(a, b)]
print(ret2)
"""
[8, 10, 12]
"""
for i in zip([1,2,3], [‘a‘,‘b‘, ‘c‘]):
print (i)
"""
(1, ‘a‘)
(2, ‘b‘)
(3, ‘c‘)
"""
from itertools import starmap
values = [[0,5], [1,6], [2,7], [3,8]]
for i in starmap(lambda x, y:(x, y, x+y), values):
print (‘%d * %d = %d‘ % i)
"""
0 * 5 = 5
1 * 6 = 7
2 * 7 = 9
3 * 8 = 11
"""
标签:values lam rom ret itertools 相加 map class tools
原文地址:https://www.cnblogs.com/xaiobong/p/10074733.html