Created
October 12, 2025 21:29
-
-
Save oshea00/a2d9abf927198534f407f4bd4ea3282d to your computer and use it in GitHub Desktop.
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
| 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