(original) (raw)

I've added a new function to itertools called 'concat'.  This function is much like chain, but takes all of the iterables as a single argument.  Thus concat(some\_iterables) is logically equivalent to chain(\*some\_iterables); the difference being that chain(\*some\_iterables) results in some\_iterables being fully expanded before the call to chain, while concat(some\_iterables) only iterates on some\_iterables as needed.  This makes concat more attractive when some\_iterables is either expensive to expand or "infinite" in length.

Thus, concat(iterable) is like:
 def concat(iterables):  
 for it in iterables:  
 for element in it:  
 yield element  

I've attached an updated itertoolsmodule.c file to this email with concat added to it.  This was based on the 2.5.1 source.

I ask that this be considered for adoption into standard python.

Thanks in advance!

\-bruce