方法1:利用list的内建函数list.sort进行排序
list.sort(key=None, reverse=False)
key:用于排序的参数,比如长度(len),数字,字母和函数等
reverse: True 降序,False (默认)升序
方法2:用sorted()函数进行排序。
sorted(list, key=None, reverse=False)
key,reverse的作用同上
两者区别:list.sort() 直接改变原列表,不返回新列表sorted() 返回新列表,不改变原列表。
参考:
【1】https://www.programiz.com/python-programming/methods/list/sort
【2】https://www.runoob.com/python/att-list-sort.html