如何打印列表的所有独特组合?
list_a = [1, 2, 3]
我想打印列表中的所有唯一组合,如此
[ [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3] ]
注:不使用任何模块
list_a = [1, 2, 3]
I want to print all the unique combinations from the list like this
[ [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3] ]
Note: Without using any module
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要 powerset refipe =“ https://docs.python.org/3/library/itertools.html” rel =“ nofollow noreferrer”>
itertools
output:
[[1],,,,,,,,,,,地[2],[3],[1,2],[1,3],[2,3],[1,2,3]]
如果您不想使用
itertools
使用列表综合或功能,您可以很容易地轻松地重新进来组合
链条 。You need a variant of the powerset recipe from
itertools
:output:
[[1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]]
If you don't want to use
itertools
you can quite easily reimplementcombinations
andchain
using list comprehensions or functions.