Skip to content

Instantly share code, notes, and snippets.

@ericls

ericls/foo.py Secret

Created January 15, 2018 18:52
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 ericls/1bbc72f9501a18dc6177d25c3e09a15a to your computer and use it in GitHub Desktop.
Save ericls/1bbc72f9501a18dc6177d25c3e09a15a to your computer and use it in GitHub Desktop.
foo.py
from itertools import combinations, chain
l = [1, 2, 3, 4, 5]
s = 5
[c for c in chain(*(combinations(l, i) for i in range(1, len(l) + 1))) if sum(c) == s]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment