Re: [Python-ideas] [Python-Dev] Overloading comparison operator for lists

This belongs on python-ideas, not python-dev. I've directed replies to this message there. Comments below. On 26May2019 21:52, Montana Burr <montana.burr@gmail.com> wrote:
map(lamdba item: item==3, [1,2,3,4,5]) I'm not sure this rates extra Python features. Personally I'm -1 on this suggestion because == traditionally returns a Boolean, NumPy notwithstanding. Your example above doesn't return a Boolean.
This is usally done by overloading dunder methods on classes. if you class subclasses a builtin eg int or list then the instances get the special behaviour.
If you go the subclass route you could do this with a mixin class (a class providing methods but little else, intended to be part of the MRO of a subclass). Cheers, Cameron Simpson <cs@cskk.id.au>

Am 27.05.19 um 06:12 schrieb Cameron Simpson:
A list comprehension seems more pythonic to me: [item == 3 for item in [1, 2, 3, 4, 5]] or, if you want it to make it lazy, use generator expression: (item == 3 for item in [1, 2, 3, 4, 5]) The latter is the direct equivalent to `map()` (in Python 3).

Am 27.05.19 um 06:12 schrieb Cameron Simpson:
A list comprehension seems more pythonic to me: [item == 3 for item in [1, 2, 3, 4, 5]] or, if you want it to make it lazy, use generator expression: (item == 3 for item in [1, 2, 3, 4, 5]) The latter is the direct equivalent to `map()` (in Python 3).
participants (2)
-
Cameron Simpson
-
Mike Müller