1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| """ @file: tt_sort.py @date: 2020-10-20 10:41 AM """ import copy from functools import cmp_to_key
def rule(a, b): if a > b: return 1 if a < b: return -1 return 0
L = [7, 4, 8, 2, 9, 6]
L2 = copy.copy(L)
L.sort(key=cmp_to_key(rule))
print(sorted(L2, key=cmp_to_key(rule))) print(L)
print(''.join([str(num) for num in L2]))
|
Checking if Disqus is accessible...