[Python-Dev] Adding concat function to itertools
Brett Cannon
brett at python.org
Fri Sep 28 19:07:40 CEST 2007
On 9/22/07, Bruce Frederiksen <dangyogi at gmail.com> wrote:
>
> 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!
>
Best thing to do is to put this up on the bug tracker
(bugs.python.org) and assign it to Raymond Hettinger as itertools is
his baby.
-Brett
More information about the Python-Dev
mailing list