[英]Permutations of list of list of lists
我想找到列表列表的排列例如:我的輸入
x = [[[1,2,3],[5,6,7]],[[8,9,10],[11,12]]]
所需的輸出應為:
[[[1,2,3],[8,9,10]],[[1,2,3],[11,12]],[[5,6,7],[8,9,10]],[[5,6,7],[11,12]]]
如您所見,我希望最里面的列表完整無缺,需要將其視為元素,然后進行組合。
我在itertools中嘗試了排列(數組)。 但這沒有用。
非常感謝您的幫助。
謝謝。
您需要itertools.product
import itertools
x = [[[1,2,3],[5,6,7]],[[8,9,10],[11,12]]]
for combo in itertools.product(*x):
print combo
輸出:
([1, 2, 3], [8, 9, 10])
([1, 2, 3], [11, 12])
([5, 6, 7], [8, 9, 10])
([5, 6, 7], [11, 12])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.