Friday, June 21, 2013

Collapse a python list that contains lists within

Use itertools
import itertools
a = [[1,2],[2],[3,4,5,6],[7],[8,9],[10]]
list(itertools.chain.from_iterable(a))

No comments:

Post a Comment