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

2019年5月28日 19:06:45 -0700

On 27/05/2019 04:52:17, Montana Burr wrote:
NumPy arrays have this awesome feature, where array == 3 does an element-wise comparison and returns a list. For example:
np.array([1,2,3,4,5])==3
returns
[False,False,True,False,False]
It would be cool if Python had similar functionality for lists.
Well, it does have:
>>> [x==3 for x in [1,2,3,4,5]]
[False, False, True, False, False]
This is IMHO much more intuitive than your construct overloading "==".
It is also more flexible (any operation can be performed on x, not just an equality comparison). So sorry, but I can see no justification for changing the Python language to do something, which can already be done, to be done in a more obscure way.
Also
  [1,2,3,4,5]==3
is already legal syntax (it evaluates to False, since the operands are not equal), so you are proposing a code-breaking change. Apologies if someone has already pointed all this out, as is very likely (I have only just (re-)joined python-ideas and may have missed the relevant posts).
Best wishes
Rob Cliffe
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to