Skip to main content
 首页 » 编程设计

python之如何在交换数字时创建列表列表

2025年05月04日15bluestorm

假设我有一个数字列表

L1 = [1,2,3] 

我希望能够在交换数字的同时从这个列表中生成许多列表。

L1 = [1,2,3]  
L2 = [2,1,3] 
L3 = [3,2,1] 
L4 = [1,3,2] 

执行此操作的最佳方法是什么?

请您参考如下方法:

from itertools import permutations 
 
print(list(permutations(L1))) 

虽然给你一个你想要的 list