So I'm working with a few pre-existing comparators that compare certain values in two tuples and return true if the first is greater than the second, false if otherwise. Here's the code for one of them:
def cmpValue(subInfo1, subInfo2):
"""
Returns True if value in (value, work) tuple subInfo1 is GREATER than
value in (value, work) tuple in subInfo2
"""
# TODO...
if subInfo1[0] > subInfo2[0]:
return True
else:
return False
Now, I have a dictionary that has numerous tuple entries of the type being compared above. I want to sort them all in reverse order, but I don't really understand how I would accomplish that. I was thinking something like:
sortedDict = sorted(subjects, key=comparator, reverse = True)
But I don't know what to pass into the comparator because each comparator takes two arguments (subInfo1, subInfo2). I cannot change the comparator functions.
if condition: return True else: return False
should bereturn condition
. – OarfishOrderedDict
from the collections module. – Verduncmp
operator. Here it is... The python wiki has an article how to convert fromcmp
tokey
. – Stalinist