# 多个列表组合成一个列表
d = [['10', '22', '34', '46'],['11', '23', '35', '47'],['18', '23', '42', '06']]
print(sum(d,[]))
"""
['10', '22', '34', '46', '11', '23', '35', '47', '18', '23', '42', '06']
"""
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]
"""
from itertools import product
a = (1, 2, 3)
b = ('A', 'B', 'C')
for i in product(a, b):
print(i)
"""
(1, 'A')
(1, 'B')
(1, 'C')
(2, 'A')
(2, 'B')
(2, 'C')
(3, 'A')
(3, 'B')
(3, 'C')
"""
from itertools import permutations
a = [1, 2, 3, 4]
s = [i for i in permutations(a,3)] # 从序列a中选出3个元素进行排列
print(s)
print(len(s))
s_number = [i[0]*100 + i[1]*10 + i[2] for i in s]
print(s_number)
print(len(s_number))
"""
[(1, 2, 3), (1, 2, 4), (1, 3, 2), (1, 3, 4), (1, 4, 2), (1, 4, 3), (2, 1, 3), (2, 1, 4), (2, 3, 1), (2, 3, 4), (2, 4, 1), (2, 4, 3), (3, 1, 2), (3, 1, 4), (3, 2, 1), (3, 2, 4), (3, 4, 1), (3, 4, 2), (4, 1, 2), (4, 1, 3), (4, 2, 1), (4, 2, 3), (4, 3, 1), (4, 3, 2)]
24
[123, 124, 132, 134, 142, 143, 213, 214, 231, 234, 241, 243, 312, 314, 321, 324, 341, 342, 412, 413, 421, 423, 431, 432]
24
"""
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
"""