[Python-checkins] r82594 - python/branches/py3k/Demo/classes/Vec.py

Alexander Belopolsky alexander.belopolsky at gmail.com
Mon Jul 5 22:42:16 CEST 2010


On Mon, Jul 5, 2010 at 4:13 PM, georg.brandl <python-checkins at python.org> wrote:
..
>         # Element-wise addition
> -        v = list(map(lambda x, y: x+y, self, other))
> -        return Vec().fromlist(v)
> +        v = list(map(operator.add, self, other))
> +        return Vec.fromlist(v)

I wonder if it would be more fitting in a 3.x demo to compute v as

v = [x + y for x, y in zip(self.v, other.v)]

or provide __iter__ and do simply

v = [x + y for x, y in zip(self, other)]

I know this suggestion may be premature before it is decided what
stays in Demo and what does not, but +import operator has caught my
eye.


More information about the Python-checkins mailing list