Skip to content

Instantly share code, notes, and snippets.

@manav148
Last active November 27, 2015 19:03
Show Gist options
  • Save manav148/551a60611ec4e71f2746 to your computer and use it in GitHub Desktop.
Save manav148/551a60611ec4e71f2746 to your computer and use it in GitHub Desktop.
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