为什么加上注释,就提示错误再试试?
import functools
#不要忘了函数定义、if等之后的冒号!!!
def cmp_ignore_case(s1,s2):
s3=s1.upper()
s4=s2.upper()
if s3==s4:
return 0
if s3<s4:
return -1
return 1
sorted_ignore_case = functools.partial(sorted, cmp=cmp_ignore_case)
#sorted_ignore_case = functools.partial(sorted, cmp=lambda s1,s2: cmp(s1.upper(), s2.upper()))
#sorted_ignore_case = functools.partial(sorted, cmp=lambda s1, s2: cmp(s1.upper(), s2.upper()))
print sorted_ignore_case(['bob', 'about', 'Zoo', 'Credit'])