Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 18
    Readers should note that whether the list items are unique is an extremely important consideration, as many algorithms will then overcount some subset (e.g. 'abccc' -> ['', 'a', 'b', 'c', 'c', 'c', 'ac', 'ac', 'ac', ...]. An easy workaround is to just shove all elements in a set before getting their permutations. Commented Sep 14, 2015 at 0:23
  • @ninjagecko Using the Set library is not efficient as each are O(n) at the best. Thus adding n functions to a set is actually O(n^2)! Commented Feb 11, 2020 at 6:02
  • 3
    From carefully reading the question, it seems that the OP is asking for the PowerSet of his list of 15 numbers, not all the combinations. I think this may be why the answers are all over the place. Commented Feb 11, 2020 at 6:53
  • @Scott Biggs: are you sure you're taking about Python here? Set insertions and lookups are O(1) average case. They're like dictionaries. They use hashing. Python doesn't have a special set library (it's in the standard library). We're inserting numbers here not functions. (It would still be inefficient to use O(2^n) memory; the proper solution for people who want combinations rather than the powerset is a simple recursive implementation, or product, etc.) Commented Feb 12, 2020 at 9:36