Skip to content

Instantly share code, notes, and snippets.

View tef's full-sized avatar
💭
Please don't try to contact me over GitHub.

tef tef

💭
Please don't try to contact me over GitHub.
View GitHub Profile
@tef
tef / gist:3688778
Created September 10, 2012 03:52 — forked from dstufft/gist:3688725
import collections
def flatten(input, seen=None):
for item in input:
if isinstance(item, collections.Iterable):
for sub in flatten(item):
yield sub
else:
yield item
@tef
tef / gist:3688768
Created September 10, 2012 03:50 — forked from dstufft/gist:3688762
import collections
def flatten(input):
stack = list(reversed(input))
while stack:
top = stack.pop()
if isinstance(top, collections.Iterable):
stack.extend(list(reversed(top)))
else:
yield top