统一用字符串首字母的大写(或小写)字母作为排序的标准即可
def cmp_ignore_case(s1, s2):
if s1[0].upper() < s2[0].upper():
return -1
if s1[0].upper() > s2[0].upper():
return 1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
def cmp_ignore_case(s1, s2):
if s1[0].upper() < s2[0].upper():
return -1
if s1[0].upper() > s2[0].upper():
return 1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2019-03-28
举报