Skip to content

Instantly share code, notes, and snippets.

@sansyrox
Created July 1, 2020 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sansyrox/c4419197bd1d37ec1aff6ce2a3d089bb to your computer and use it in GitHub Desktop.
Save sansyrox/c4419197bd1d37ec1aff6ce2a3d089bb to your computer and use it in GitHub Desktop.
Custom Comparator sort in python
from functools import cmp_to_key
sorted(mylist, key=cmp_to_key(compare))
def compare(item1, item2):
if fitness(item1) < fitness(item2):
return -1
elif fitness(item1) > fitness(item2):
return 1
else:
return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment