请教有关排列组合的问题
qpython吧
全部回复
仅看楼主
level 6
hzyjj1212 楼主
例:有列表list1=[1,[2,3],4,[5,6,7]],列表的长度不确定
如何生成排列组合:[[1,2,4,5],[1,2,4,6],[1,2,4,7],[1,3,4,5],[1,3,4,6],[1,3,4,7]
跪求!!
2015年08月20日 06点08分 1
level 6
hzyjj1212 楼主
def comb(lst):
tmp1=[]
for x in lst:
if type(x) is list:
tmp1.append(x)
else:
tmp1.append([x])
tmp=[[]]
for x in tmp1:
new_lst=[]
for i in range(len(tmp1)):
for z in x:
new_lst.append(tmp1[i]+[z])
tmp1=new_lst
return new_lst
2015年08月29日 03点08分 4
1