[Python-ideas] + operator on generators

David Mertz mertz at gnosis.cx
Mon Jun 26 12:55:19 EDT 2017


On Sun, Jun 25, 2017 at 8:23 PM, Steven D'Aprano <steve at pearwood.info>
wrote:

> On Sun, Jun 25, 2017 at 02:06:54PM +0200, lucas via Python-ideas wrote:
>
> I have a counter-proposal: introduce the iterator chaining operator "&":
>
>     iterable & iterable --> itertools.chain(iterable, iterable)
>

In [1]: import numpy as np
In [2]: import itertools
In [3]: a, b = np.array([1,2,3]), np.array([4,5,6])
In [4]: a & b
Out[4]: array([0, 0, 2])
In [5]: a + b
Out[5]: array([5, 7, 9])
In [6]: list(itertools.chain(a, b))
Out[6]: [1, 2, 3, 4, 5, 6]

These are all distinct, useful, and well-defined behaviors.

-- 
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170626/ca413e3a/attachment-0001.html>


More information about the Python-ideas mailing list