self-confidence,the source of all the power

导航

python 列表排序

排序有两个函数可用,如对列表L进行排序:

则可以用

L.sort(),改变原来列表顺序,

sorted(L),对L排序后并返回排序后的新列表。

如L=[(1,23),(2,34),(3,12)]

对成员中的第二个数排序则可以:

L.sort(key=lambda item:item[1]).

简单记录。。。。哈

posted on 2011-11-15 17:08  漩涡鸣人  阅读(482)  评论(0编辑  收藏  举报