The Python Oracle

how to make sortable datatype in Python?

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Sunrise at the Stream

--

Chapters
00:00 Question
01:16 Accepted answer (Score 13)
01:35 Thank you

--

Full question
https://stackoverflow.com/questions/4630...

Accepted answer links:
http://wiki.python.org/moin/HowTo/Sortin.../

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #sorting #datastructures

#avk47



ACCEPTED ANSWER

Score 13


Check out http://wiki.python.org/moin/HowTo/Sorting/

You want to override __lt__ in your class for the built in sort function to work the way you described.