Last active
November 27, 2015 19:03
-
-
Save manav148/551a60611ec4e71f2746 to your computer and use it in GitHub Desktop.
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
def recurse(li, depth = 3, result =[]): | |
if depth == 0: | |
return result | |
if not result: | |
return recurse(li, depth -1, zip(li) if depth > 1 else li) | |
else: | |
nr = [ (x,) + y for x in li for y in result] | |
return recurse(li, depth -1, nr) | |
recurse([0,1]) | |
def recurse_trans(li, depth = 3): | |
result = zip(li[:]) if depth > 1 else li | |
depth -= 1 | |
while True: | |
if depth <= 0: | |
break | |
nr = [(x,) + y for x in li for y in result] | |
result = nr | |
depth -= 1 | |
return result | |
recurse_trans([0,1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment