Revision 1711
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/iters.py | ||
---|---|---|
1 |
# Iterators |
|
2 |
|
|
3 |
def flatten(outer_iter): |
|
4 |
for iter_ in outer_iter: |
|
5 |
for el in iter_: yield el |
|
6 |
|
|
7 |
def flatten_n(outer_iter, depth=2): |
|
8 |
if depth < 2: return outer_iter |
|
9 |
elif depth == 2: return flatten(outer_iter) |
|
10 |
else: return flatten(flatten_n(outer_iter, depth-1)) |
Also available in: Unified diff
Added iters.py