生成组合 [英] Generating Combinations
本文介绍了生成组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每次我必须这样做时,我都会发明"一种不同的方式.是时候标准化了.我怀疑有一些我忽略的默认命令准备执行此操作,所以如果问题太琐碎,我提前道歉.
Every time I have to do this I "invent" a different way. Time to standardize. I suspect there is some default command I overlooked ready to do this, so I am sorry in advance if the question is too trivial.
什么是更好的(内存、性能)获取方式:
What is the better (memory, performance) way to get:
combinations[{1,2,3},2] = {{1,2},{1,3},{2,3}}
当然是输入列表中的任意元素.
with arbitrary elements in the input list, of course.
推荐答案
Subsets[{1, 2, 3}, {2}]
是内置方式.
这篇关于生成组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文