主页
Python
Python List sort() 方法
demo_ref_list_sort4
运行 ❯
×
更改方向
保存代码
更改主题
# A function that returns the length of the value: def myFunc(e): return len(e) cars = ['Ford', 'Mitsubishi', 'BMW', 'VW'] cars.sort(reverse=True, key=myFunc) print(cars)
['Mitsubishi', 'Ford'', 'BMW', 'VW']