Python内置函数sorted()可以对列表、元组、字典、集合、字符串、range对象以及其他可迭代对象进行排序,返回排序后的列表,支持使用key参数指定排序规则,支持reverse参数指定升序或者降序...>>> sorted(range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
#降序排列
>>> sorted(range(10), reverse=True)
[9, 8,...'d']
>>> sorted(d.keys())
['a', 'b', 'c', 'd']
#对字典中的值进行排序
>>> sorted(d.values())
[0, 2, 3, 5]
#对字典中的元素进行排序...>>> sorted(x)
['aba', 'aec', 'cc', 'da']
#按字符串长度进行排序
>>> sorted(x, key=len)
['da', 'cc', 'aba', 'aec...>>> sorted(x, key=lambda i:-len(i))
['aba', 'aec', 'da', 'cc']
#按字符串下标为1的字符进行排序
>>> sorted(x, key=lambda