Is there a way to sort custom objects in a custom way in Python? <p>I'm using web.py to spin up endpoints and as such, I present a list of endpoints like so</p> <pre><code>urls = ('/(.*)', 'base', '/shapes/(.*)', 'shapes', '/sounds/(.*)', 'sounds', '/shapes/rectangualar/(.*)', 'rectangualarShapes', '/sounds/loud/(.*)', 'loudSounds') </code></pre> <p>As web.py will see the first one and match all possible endpoints to it, they need to be ordered, most specific first, i.e.</p> <pre><code>urls = ('/shapes/rectangualar/(.*)', 'rectangualarShapes', '/shapes/(.*)', 'shapes', '/sounds/loud/(.*)', 'loudSounds' '/shapes/(.*)', 'shapes', '/sounds/(.*)', 'sounds', '/(.*)', 'base') </code></pre> <p>I want to order these, by URI. Firstly if there's a simple way to do it, as tuples, it would be great but I figure I need to convert them to objects</p> <pre><code>class Endpoint(object): def __init__(self, id, classname): self.id = id self.classname = classname def getId(item): return self.id </code></pre> <p>and <code>print sorted(endpointList, key=id)</code> them. How would I do this in Python 3+? I've come across comparator functions but it seems they are deprecated.</p> <p>What is the best way to do custom sorting?</p>