Skip to content

Instantly share code, notes, and snippets.

@eyaltrabelsi
Created July 9, 2019 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eyaltrabelsi/70ac224ec7ee1e02c471b180234b79f1 to your computer and use it in GitHub Desktop.
Save eyaltrabelsi/70ac224ec7ee1e02c471b180234b79f1 to your computer and use it in GitHub Desktop.
Python trick Creating a combination of k things from an iterable of n
>>> import itertools
>>> bills = [20, 20, 20, 10, 10, 10, 10, 10, 5, 5, 1, 1, 1, 1, 1]
>>> list(itertools.combinations(bills, 3))
[(20, 20, 20), (20, 20, 10), (20, 20, 10), ... ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment