Python 3000 idea -- + on iterables -> itertools.chain

John Reese jtr at ofb.net
Sun Nov 12 19:46:26 EST 2006


It seems like it would be clear and mostly backwards compatible if the
+ operator on any iterables created a new iterable that iterated
throught first its left operand and then its right, in the style of
itertools.chain.  This would allow summation of generator expressions,
among other things, to have the obvious meaning.

Any thoughts?  Has this been discussed before?  I didn't see it
mentioned in PEP 3100.

The exception to the compatibility argument is of course those
iterables for which + is already defined, like tuples and lists, for
that set of code that assumes that the result is of that same type,
explicitly or implicitly by calling len or indexing or whathaveyou.
In those cases, you could call tuple or list on the result.  There are
any number of other things in Python 3000 switching from lists to
one-at-a-time iterators, like dict.items(), so presumably this form of
incompatibility isn't a showstopper.



More information about the Python-list mailing list