源代码
# A function that returns the length of the value: def myFunc(e): return len(e) cars = ['Porsche', 'Audi', 'BMW', 'VW'] cars.sort(key=myFunc) print(cars)
运行结果