Ok, now I'm mildly curious to knpw:
What is the justification for causing list == 3 to evaluate to False,
besides the obvious "a list cannot equal a number"?
On Tue, May 28, 2019 at 9:34 PM Montana Burr <montana.burr(a)gmail.com> wrote:
> Ok, now I'm mildly curious to knpw:
> What is the justification for causing list == 3 to evaluate to False,
> besides the obvious "a list cannot equal a number"?
> On Tue, May 28, 2019 at 7:52 PM Rob Cliffe <rob.cliffe(a)btinternet.com>
>> 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.
>> 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
> Overall rating