从python列表中获取元素的唯一组合 [英] Get unique combinations of elements from a python list
问题描述
这个主题是关于寻找唯一的组合,而另一个主题是关于寻找所有的组合.
This topic is about finding unique combinations while the other topic is about finding ALL combinations.
如果我有python列表:
If I have a python list:
L = [1,2,3,4]
从以下列表中获取3个元素的所有可能唯一组合的最佳方法是什么:
what's the best way to get all the possible unique combinations of 3 elements from the list like below:
["1,2,3", "1,2,4", "2,3,4", "3,4,1"]
组合中元素的顺序无关紧要.例如,"1,2,3"
和"3,2,1"
将被视为相同的组合.
The order of the elements in the combinations doesn't matter. For example, "1,2,3"
and "3,2,1"
will be considered the same combination.
我可能可以编写一些循环来执行此操作,但我认为可能会有一个单行代码可以执行相同的操作.
I can probably write a few loops to do this but I think there might be a one-liner which can do the same.
推荐答案
您需要
这篇关于从python列表中获取元素的唯一组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!