格式:
sorted(list) / sorted(list, 函数)
官网解释:
sorted
(iterable[, cmp[, key[, reverse]]])Return a new sorted list from the items in iterable. #返回一个排序过的新的可迭代的列表
官网给出的详细sorted用法:
https://docs.python.org/2/howto/sorting.html#sortinghowto
#default
ls = ['You', 'can', 'Do', 'that'];
print sorted(ls);
#self
def cmp(s1, s2):
u1 = s1.upper(); #upper 将所有字符串转为大写 ----> lower 将所有字符串转为小写
u2 = s2.upper();
if u1 < u2:
return -1;
if u1 > u2:
return 1;
return 0;
print sorted(ls, cmp)