比較大小與排列順序
怎么理解“如果 x 應該排在 y 的前面,返回 -1,如果 x 應該排在 y 的后面,返回 1。如果 x 和 y 相等,返回 0”
def cmp_ignore_case(s1, s2):
??? if s1.lower()>s2.lower():
??????? return -1
??? if s1.lower()<s2.lower():
??????? return 1
??? return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'],cmp_ignore_case) 結果是倒序
2019-06-28