import copy
a=["1","2","3"]
b=["4","5","6","7"]
c=["10","8","9"]
def insert( sum, values ):
if sum == []:
for value in values:
sum.append( [value] )
return
tmp = copy.deepcopy(sum)
for item in tmp:
for value in values:
sum.append( item + [value] )
sum.remove( item )
if __name__ == "__main__":
sum = []
for values in [a,b,c]:
insert( sum, values )
for i in sum:
print(i)
结果:
['1', '4', '10']
['1', '4', '8']
['1', '4', '9']
['1', '5', '10']
['1', '5', '8']
['1', '5', '9']
['1', '6', '10']
['1', '6', '8']
['1', '6', '9']
['1', '7', '10']
['1', '7', '8']
['1', '7', '9']
['2', '4', '10']
['2', '4', '8']
['2', '4', '9']
['2', '5', '10']
['2', '5', '8']
['2', '5', '9']
['2', '6', '10']
['2', '6', '8']
['2', '6', '9']
['2', '7', '10']
['2', '7', '8']
['2', '7', '9']
['3', '4', '10']
['3', '4', '8']
['3', '4', '9']
['3', '5', '10']
['3', '5', '8']
['3', '5', '9']
['3', '6', '10']
['3', '6', '8']
['3', '6', '9']
['3', '7', '10']
['3', '7', '8']
['3', '7', '9']
当时我是这么写的,感觉很不 pythonic
哈哈哈,又学到一招