Don't forget to also checkout my second blog containing articles to all other related ICT topics!!
Thursday, May 3, 2012
Itertools chain method explained
Itertools chain makes an iterator that returns elements from the first iterable until it is exhausted, then proceeds to the next iterable, until all of the iterables are exhausted.
#Goal: Chain iterables into 1 iterable
from itertools import chain
numbers1= [1, 2, 3]
numbers2 = range(4,8) #range excludes to index
for number in chain(numbers1, numbers2):
print number
No comments:
Post a Comment