Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python sort with comparator

def mycmp(a, b):
	if a < b:
		return -1
	elif a > b:
		return 1
	return 0
sorted(lst, key=functools.cmp_to_key(mycmp))
# functools.cmp_to_key converts the mycmp to a "key function",
# which returns an object that can be sorted accoding to mycmp
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #sort #comparator
ADD COMMENT
Topic
Name
8+8 =