[Python-Dev] Overloading comparison operator for lists
steve at pearwood.info
Wed May 29 08:44:25 EDT 2019
As Cameron Simpson already pointed out, your query is off-topic for the
Python-Dev mailing list and should be taken to the Python-Ideas mailing
list, which is for speculative discussion of new designs.
Like Cameron, I've CCed Python-Ideas. Please send any follow-ups to that
list and not Python-Dev.
You asked this question:
On Tue, May 28, 2019 at 09:35:51PM -0600, Montana Burr 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"?
I concur with Terry Reedy -- what more justification is needed? A list
cannot equal a number, so the default behaviour ought to be to return
False. What would you have the default behaviour be?
People have already suggested that getting the numpy-style behaviour is
simple with a list comprehension, but the other technique is to subclass
list, override ``__eq__`` and give it the behaviour you want.
More information about the Python-Dev