生成 python 列表的所有类型的唯一可能组合
你好,我需要知道如何以如此有趣的方式获得列表的所有唯一可能组合:
例如:
myLIST=[70,90,100]
我想制作两个或一个数字的唯一组合.. IE;
final_list=[ { [100 , 70] , [90] } , { [100 , 90] , [70] }]
在这个例子中: 可能只有这两个子列表;
作为;如果我采取 [{ [70,100] , [90] }]
或 [{[90,100],[70]}]
子列表组合开始重复,
Note : for a list of 5 elements;i just need those combination lists which have either 3 elemnts or two elements
例如:myLIST=[10,20,30,40,50]
final_list=[{[10,30,50],[20,40]}] , {[10,50],[20,50,30]}
等等..
这里我只采用了大小为 2 或 3 的子列表
hello i need to know how can i get all the unique possible combinations of a list in such an interesting way:
eg:
myLIST=[70,90,100]
i want to make either two or a single digit unique combination..
i.e;
final_list=[ { [100 , 70] , [90] } , { [100 , 90] , [70] }]
here in this example:
there possible only these two sublists;
as; if i take [{ [70,100] , [90] }]
or [{[90,100],[70]}]
the sublists combinations starts repeating
Note : for a list of 5 elements;i just need those combination lists which have either 3 elemnts or two elements
eg:myLIST=[10,20,30,40,50]
final_list=[{[10,30,50],[20,40]}] , {[10,50],[20,50,30]}
and so on..
here i have taken only the sublists of size 2 or 3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

您可以使用 itertools(内置的 python 库)生成列表组合:
returns:
您可以在此处找到有关 itertools 的更多信息:
https://datagy.io/python-combinations-of-a-list/< /a>
You can use itertools (a built-in python library) to generate combinations of lists:
returns:
You can find more information about itertools here:
https://datagy.io/python-combinations-of-a-list/