Don't forget to also checkout my second blog containing articles to all other related ICT topics!!

Thursday, May 3, 2012

Itertools chain.from_iterable method explained

Gets chained inputs from a single iterable argument that is evaluated lazily
import itertools
numbers = [[1,2,3,4], [5,6,7,8]]

flattened = list(itertools.chain.from_iterable(numbers))
print flattened

[1, 2, 3, 4, 5, 6, 7, 8]

No comments:

Post a Comment