def sorted_with_cmp(sequence, cmp_func, **kwargs):
# sort with a cmp func which works under both Python 2 and 3
if sys.version_info[0] == 3:
from functools import cmp_to_key
key = cmp_to_key(cmp_func)
def do_sort(x):
return sorted(x, key=key, **kwargs)
else:
def do_sort(x):
return sorted(x, cmp=cmp_func, **kwargs)
return do_sort(sequence)
评论列表
文章目录