如图,最近想实现一个小功能:多个
数组
中,数据之间的组合。绞尽脑汁,无论多少个数组,想用一个函数来解决这个问题。
a = [1,2,3,4,6]
b = [12,13,14,15,16]
c = [22,23,24,25,26]
A = [a,b,c]
def getPlans(lis,jude=True):
if jude: lis = [[[i] for i in lis[0]]] + lis[1:]
if len(lis) > 2:
for i in lis[0]:
for j in lis[1]:
getPlans([[i + [j]]] + lis[2:], False)
elif len(lis) == 2:
for i in lis[0]:
for j in lis[1]:
print(i + [j])
getPlans(A)
>>>[1, 12, 22]
[1, 12, 23]
[1, 12, 24]
....
[6, 16, 22]
[6, 16, 23]
[6, 16, 24]
[6, 16, 25]
[6, 16, 26]