Skip to content

Instantly share code, notes, and snippets.

@cameronp98
Created January 9, 2014 22:18
Show Gist options
  • Save cameronp98/8343127 to your computer and use it in GitHub Desktop.
Save cameronp98/8343127 to your computer and use it in GitHub Desktop.
Randomly nested list generator in Python
from random import randint
def sequence(length=3, depth=0, max_depth=2):
for i in range(1,length):
if randint(0,1) and depth <= max_depth:
yield list(sequence(3, depth+1))
else:
yield randint(1,9)
if __name__ = "__main__":
print(list(sequence()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment