how to use custom comparitor for sorting pyhon code example
Example: how to use custom comparitor in sorting pyhon
def compare(item1, item2):
if fitness(item1) < fitness(item2):
return -1
elif fitness(item1) > fitness(item2):
return 1
else:
return 0
# Calling
list.sort(key=compare)