Skip to content

Instantly share code, notes, and snippets.

@mutaku
Created March 13, 2012 02:55
Show Gist options
  • Save mutaku/2026291 to your computer and use it in GitHub Desktop.
Save mutaku/2026291 to your computer and use it in GitHub Desktop.
iters of iters of iters of lists of lists of lists
x = [[[1, 2, 3, 4], [9, 8, 7, 6]], [[10, 20, 30, 40], [90, 80, 70, 60]]]
from itertools import chain
[[y[i] for y in list(chain.from_iterable(x))] for i in range(0,len(x[0][0]))]
@mutaku
Copy link
Author

mutaku commented Mar 13, 2012

final = []
for i range(0,len(x[0][0])):
    this = []
    for n in x:
        if n[i] and n[i] < 200:
            this.append(n[i])
    final.append(n)

@mutaku
Copy link
Author

mutaku commented Mar 13, 2012

# catch NoneType and only if less than 200
from itertools import chain
[[y[i] for y in list(chain.from_iterable(x)) if y[i] and y[i] < 200] for i in range(0,len(x[0][0]))]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment