Skip to content

Instantly share code, notes, and snippets.

@aaronshaver
Created April 11, 2022 21:45
Show Gist options
  • Save aaronshaver/bd1d73bf0be1dd64e8cc8dc52ac6f671 to your computer and use it in GitHub Desktop.
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
# 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