本帖最后由 cdtits 于 2012-08-02 15:24 编辑
回复 9# ssfjhh - Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
- Type "copyright", "credits" or "license()" for more information.
- >>> a = [('a', '23'), ('b', '1'), ('c', '21'), ('d', '22'), ('e', '2'), ('f', '11')]
- >>> a
- [('a', '23'), ('b', '1'), ('c', '21'), ('d', '22'), ('e', '2'), ('f', '11')]
- >>> a.sort(key=lambda x:x[1])
- >>> a
- [('b', '1'), ('f', '11'), ('e', '2'), ('c', '21'), ('d', '22'), ('a', '23')]
- >>> a.sort(key=lambda x:int(x[1]))
- >>> a
- [('b', '1'), ('e', '2'), ('f', '11'), ('c', '21'), ('d', '22'), ('a', '23')]
- >>>
复制代码 |