[关闭]
@zhengyuhong 2016-02-06T09:27:37.000000Z 字数 401 阅读 945

python

posts


list

sort

list.sort(func=None, key=None, reverse=False) #修改原有的list

  1. students = [('john', 'A', 15), ('jane', 'B', 12), ('dave', 'B', 10)]
  2. students.sort(key = lambda stu : std[2], reverse=False)

sorted

sorted(iterable[, cmp[, key[, reverse]]]) #返回一个新的list
sorted(iterable, cmp=None, key=None, reverse=False)

  1. students = [('john', 'A', 15), ('jane', 'B', 12), ('dave', 'B', 10)]
  2. c = lambda x, y : cmp(x[2], y[2])
  3. students_new = sorted(students, cmp = c)
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注