What is the difference between chain and chain.from_iterable in itertools?
The first takes 0 or more arguments, each an iterable, the second one takes one argument which is expected to produce the iterables: from itertools import chain chain(list1, list2, list3) iterables = [list1, list2, list3] chain.from_iterable(iterables) but iterables can be any iterator that yields the iterables: def gen_iterables(): for i in range(10): yield range(i) itertools.chain.from_iterable(gen_iterables()) … Read more