怎样实现倒序,我借鉴了前面的自定义排序函数,但一直无效?
import functools
sorted_ignore_case = functools.partial(sorted,cmp=lambda s1,s2:cmp(s1.upper(),s2.upper()))
print sorted_ignore_case(['bob', 'about', 'Zoo', 'Credit'])
print sorted(['bob', 'about', 'Zoo', 'Credit'])
def reversed_cmp(x, y):
if x > y:
return -1
if x < y:
return 1
return 0
print sorted([36, 5, 12, 9, 21], reversed_cmp)
sorted_ignore_case = functools.partial(sorted,reversed_cmp=lambda s1,s2:reversed_cmp(s1.upper(),s2.upper()))
print sorted_ignore_case(['bob', 'about', 'Zoo', 'Credit'])
我借鉴了前面2-7的自定义排序函数,但一直无效?