[Python-Dev] itertools.chain should take an iterable ?

Raymond Hettinger raymond.hettinger at verizon.net
Fri Sep 2 14:12:41 CEST 2005

> >>Well this happened after I tried instinctively
> >>itertools.chain(child.method() for child in self).

As Jack's note points out, your proposed signature is incompatible with
the one we have now.  I recommend creating your own version:

     def paolino_chain(iterables):
         for it in iterables:
             for element in it:
                 yield element

    >>> list(chain(c+c for c in string.ascii_uppercase))
    ['A', 'A', 'B', 'B', 'C', 'C', 'D', 'D', 'E', 'E', 'F', 'F',
     'G', 'G',   'H', 'H', 'I', 'I', 'J', 'J', 'K', 'K', 'L', 'L',
     'M', 'M', 'N', 'N', 'O', 'O', 'P', 'P', 'Q', 'Q', 'R', 'R',
     'S', 'S', 'T', 'T', 'U', 'U', 'V', 'V', 'W', 'W', 'X', 'X', 
     'Y', 'Y', 'Z', 'Z']

> >>Is there a reason for this signature ?

It was handy for the use cases I had in mind when creating the function.
Also it was styled after a version in another language where it had
proven successful.

> > This is more suited to comp.lang.python
> >
> Why ? I'm not asking for help ,I'm asking why itertools library is
> implemented like that and if it is possible to clean it.

The newsgroup would have guided you to the solution listed above.  If
you want to request a new feature, please use SourceForge.


More information about the Python-Dev mailing list