I'm using web.py to spin up endpoints and as such, I present a list of endpoints like so
urls = ('/(.*)', 'base',
'/shapes/(.*)', 'shapes',
'/sounds/(.*)', 'sounds',
'/shapes/rectangualar/(.*)', 'rectangualarShapes',
'/sounds/loud/(.*)', 'loudSounds')
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.
urls = ('/shapes/rectangualar/(.*)', 'rectangualarShapes',
'/shapes/(.*)', 'shapes',
'/sounds/loud/(.*)', 'loudSounds'
'/shapes/(.*)', 'shapes',
'/sounds/(.*)', 'sounds',
'/(.*)', 'base')
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
class Endpoint(object):
def __init__(self, id, classname):
self.id = id
self.classname = classname
def getId(item):
return self.id
and print sorted(endpointList, key=id) them. How would I do this in Python 3+? I've come across comparator functions but it seems they are deprecated.
What is the best way to do custom sorting?