Skip to content

Instantly share code, notes, and snippets.

@james-m
Created May 22, 2013 19:41
Show Gist options
  • Save james-m/5630307 to your computer and use it in GitHub Desktop.
Save james-m/5630307 to your computer and use it in GitHub Desktop.
import random
import itertools
x = [[random.randint(0, 100) for i in range(random.randint(1, 5))] for z in range(10)]
print x
def walk(seq):
for sub in itertools.izip_longest(*seq):
for i in sub:
if i is None:
continue
yield i
for n in walk(x):
print n
output:
$ python test_walk.py
[[65, 39, 17, 33, 27], [35, 26], [96], [43, 88, 28, 49], [19, 61, 13, 50], [19, 77, 46, 57], [36, 71], [72], [17, 25, 68, 35, 32], [60, 64, 35, 63]]
65
35
96
43
19
19
36
72
17
60
39
26
88
61
77
71
25
64
17
28
13
46
68
35
33
49
50
57
35
63
27
32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment