473,320 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Re: Question about sorted in Python 3.0rc1

josh logan <de************@gmail.comwrote:
>sorted(P) # throws TypeError: unorderable types Player() < Player()

The sorted function works when I define __lt__.
I must be misreading the documentation, because I read for the
documentation __cmp__ that it is called if none of the other rich
comparison functions are defined.
You're either misreading or forgetting that __eq__ and __ne__,
which you define, are rich comparison functions. __cmp__ will only
be called for a comparison when *none* of the rich comparison
functions are defined, not just the one in question.

--
\S -- si***@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
"Frankly I have no feelings towards penguins one way or the other"
-- Arthur C. Clarke
her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
Sep 22 '08 #1
1 1282
On Sep 22, 7:32*am, Sion Arrowsmith <si...@chiark.greenend.org.uk>
wrote:
josh logan *<dear.jay.lo...@gmail.comwrote:
sorted(P) # throws TypeError: unorderable types Player() < Player()
The sorted function works when I define __lt__.
I must be misreading the documentation, because I read for the
documentation __cmp__ that it is called if none of the other rich
comparison functions are defined.

You're either misreading or forgetting that __eq__ and __ne__,
which you define, are rich comparison functions. __cmp__ will only
be called for a comparison when *none* of the rich comparison
functions are defined, not just the one in question.

--
\S -- si...@chiark.greenend.org.uk --http://www.chaos.org.uk/~sion/
* *"Frankly I have no feelings towards penguins one way or the other"
* * * * -- Arthur C. Clarke
* *her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
Hello Sion,

When I don't define the __eq__ and __ne__ comparison functions, the
same unexpected behavior occurs.
Sep 22 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Peter Otten | last post by:
josh logan wrote: Python's sort algorithm is guaranteed to be stable; therefore you can sort twice: ordered = sorted(players, key=lambda p: p.fname, reverse=True) ordered.sort(key=lambda p:...
0
by: Terry Reedy | last post by:
josh logan wrote: Here is a minimal example showing the problematic behavior. class Int(): def __init__(self, i): self.i = i def __cmp__(self, other): return cmp(self.i, other.i)
0
by: Hrvoje Niksic | last post by:
josh logan <dear.jay.logan@gmail.comwrites: Thanks, I've now filed a bug report for that. It looks like an oversight.
2
by: Mark Tolonen | last post by:
I don't understand the behavior of the interpreter in Python 3.0. I am working at a command prompt in Windows (US English), which has a terminal encoding of cp437. In Python 2.5: Python 2.5...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.