Last active
March 19, 2022 19:04
-
-
Save offlinehacker/6340434 to your computer and use it in GitHub Desktop.
Devides list in all posible sublists, without repetitions
This file contains 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 combinations | |
def divide(l, p={}): | |
for v in (j for i in xrange(1, len(l) + 1) for j in combinations(l, i)): | |
r = tuple(set(l) - set(v)) | |
for s in devide(r): | |
t = (v,) + (s if s else tuple()) | |
if frozenset(t) in p: continue | |
else: yield t; p[frozenset(t)] = True | |
if not l: yield tuple() | |
list(devide([1,2,3,4,5])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment