python 在列表中添加元组元素,按照元组第一个值进行排序

 

>>> import bisect
>>> scores = [(100, 'perl'), (200, 'tcl'), (400, 'lua'), (500, 'python')]
>>> bisect.insort(scores, (300, 'ruby'))
>>> scores
[(100, 'perl'), (200, 'tcl'), (300, 'ruby'), (400, 'lua'), (500, 'python')]

 

posted @ 2018-11-27 19:25  anobscureretreat  阅读(7712)  评论(0编辑  收藏  举报