Created
April 11, 2022 21:45
-
-
Save aaronshaver/bd1d73bf0be1dd64e8cc8dc52ac6f671 to your computer and use it in GitHub Desktop.
IterTools .combinations() to create all possible subsets, of all sizes, of a larger set
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create all combinations of all subsets, excluding "groups" of single numbers | |
# e.g. for below would create the original nums, groups of 4, groups of 3, groups of 2 | |
import itertools | |
nums = [3,5,9,1,3] | |
groups = [] | |
for group_size in range(2, len(nums) + 1): | |
for subset in itertools.combinations(nums, group_size): | |
groups.append(subset) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment