Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
多个整数列表上的Python置换_Python_List_Permutation_Itertools - Fatal编程技术网

多个整数列表上的Python置换

多个整数列表上的Python置换,python,list,permutation,itertools,Python,List,Permutation,Itertools,我有一个列表字典,其中每个列表表示变量(键)的所有可能值: 我想创建包含这些值的所有可能排列(笛卡尔积)的元组,以便确定哪些值组合是正确的 # example perms = [(4, 1, 7, 2), (4, 1, 5, 2), (4, 1, 6, 2), (4, 3, 7, 2), ... , (8, 3, 6, 2)] 有没有一个简单的方法?我问了另一个问题,用itertools置换法解决了。然而,我很困惑如何从多个列表中选择一个数字进行排列 这个需要一个产品 >>>

我有一个列表字典,其中每个列表表示变量(键)的所有可能值:

我想创建包含这些值的所有可能排列(笛卡尔积)的元组,以便确定哪些值组合是正确的

# example
perms = [(4, 1, 7, 2), (4, 1, 5, 2), (4, 1, 6, 2), (4, 3, 7, 2), ... , (8, 3, 6, 2)]

有没有一个简单的方法?我问了另一个问题,用itertools置换法解决了。然而,我很困惑如何从多个列表中选择一个数字进行排列

这个需要一个
产品

>>> from itertools import product
>>> list(product(*values.values()))
[(4, 1, 7, 2),
 (4, 1, 5, 2),
 (4, 1, 6, 2),
 (4, 3, 7, 2),
 (4, 3, 5, 2),
 ...
]
>>> from itertools import product
>>> list(product(*values.values()))
[(4, 1, 7, 2),
 (4, 1, 5, 2),
 (4, 1, 6, 2),
 (4, 3, 7, 2),
 (4, 3, 5, 2),
 ...
]