Python的列表排序

来源:互联网 发布:罗技鼠标怎么编程 编辑:程序博客网 时间:2024/06/05 11:57

列表元素如果全是元组,元组中又有数字,那么 sorted 也可对其进行排序

print log_to_arr()print sorted(log_to_arr())

运行结果:

[(72044, 'GET / HTTP/1.0'), (872302, 'GET /home HTTP/1.0'), (370689, 'GET /search?position_times=2 HTTP/1.0'), (155704, 'GET /member/people/119 HTTP/1.0'), (12130, 'GET /logout HTTP/1.0')][(12130, 'GET /logout HTTP/1.0'), (72044, 'GET / HTTP/1.0'), (155704, 'GET /member/people/119 HTTP/1.0'), (370689, 'GET /search?position_times=2 HTTP/1.0'), (872302, 'GET /home HTTP/1.0')]


回归,师哥布置分析日志任务,早前做过一次,但这次要求不一样,复习+基础做起,挺好。