1、sort是针对列表进行排序的,改变列表本身
>>> a1=[3,2,6,1]
>>> a1.sort()
>>> a1
[1, 2, 3, 6]
2、字典采用sorted
>>> d={'c': 2, 'f': 12, 'a': 1, 'b': 4}
>>>
>>> a1=sorted(d.items())
>>> a1
[('a', 1), ('b', 4), ('c', 2), ('f', 12)]
>>>
>>> f=zip(d.keys(),d.values())
>>>
>>> a2=sorted(f)
>>> a2
[('a', 1), ('b', 4), ('c', 2), ('f', 12)]
网友评论