有没有更简单和严谨的方法
有没有更简单方法
def cmp_ignore_case(s1, s2):
n = len(s1)
m = len(s2)
x = 0
ret = 0
if n < m:
x = n
ret = 1
elif n > m:
x = m
ret = -1
else:
x = m
ret = 0
i = 0
while(True):
if s1[i].upper() > s2[i].upper():
return 1
elif s1[i].upper() == s2[i].upper():
i += 1
if i>=x:
break
else:
continue
else:
return -1
i += 1
if i>=x:
break
return ret
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)