Skip to content

Instantly share code, notes, and snippets.

@oshea00
Created October 12, 2025 21:29
Show Gist options
  • Select an option

  • Save oshea00/a2d9abf927198534f407f4bd4ea3282d to your computer and use it in GitHub Desktop.

Select an option

Save oshea00/a2d9abf927198534f407f4bd4ea3282d to your computer and use it in GitHub Desktop.
from itertools import permutations
items = ["a", "b", "c"]
perms = permutations(items)
for p in perms:
print(p)
# list combinations
from itertools import combinations
items = ["a", "b", "c"]
combs = combinations(items, 2)
for c in combs:
print(c)
# list all subsets
from itertools import chain, combinations
def all_subsets(items):
return chain.from_iterable(combinations(items, r) for r in range(len(items) + 1))
items = ["a", "b", "c"]
subsets = all_subsets(items)
for s in subsets:
print(s)
# list cartesian product
from itertools import product
items1 = ["A", "B"]
items2 = range(2)
cartesian_prod = product(items1, items2)
for cp in cartesian_prod:
print(cp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment