2 of 2
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Not my idea, but I think this is better:
import collections
def flatten(lst):
for item in lst:
if isinstance(item, collections.Iterable) and not isinstance(item, basestring):
for sublst in flatten(item):
yield sublst
else:
yield item
janos
- 112.9k
- 15
- 154
- 396
default