Python内置函数sorted()可以对列表、元组、字典、集合、字符串、range对象以及其他可迭代对象进行排序,返回排序后的列表,支持使用key参数指定排序规则,支持reverse参数指定升序或者降序...3, 4, 5, 6, 7, 8, 9]
#降序排列
>>> sorted(range(10), reverse=True)
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
#对字符串中的字符升序排序...>>> sorted(d)
['a', 'b', 'c', 'd']
>>> sorted(d.keys())
['a', 'b', 'c', 'd']
#对字典中的值进行排序
>>> sorted(...d.values())
[0, 2, 3, 5]
#对字典中的元素进行排序
>>> sorted(d.items())
[('a', 3), ('b', 2), ('c', 5), ('d', 0)]...i:i[1])
['da', 'aba', 'cc', 'aec']
>>> from random import randint
#列表推导式,生成包含10个子列表的列表,每个子列表中包含10个随机数