请问使用sorted()函数对列表进行临时排序中“如何按与字母顺序相反的顺序显示列表”
书里有这样一串代码
cars = [‘bmw’,’audi’,’toyota’,’subaru’]
print(“Here is the original list:”)
print(cars)
print(“\nHere is the sorted list:”)
print(sorted(cars))
print(“\nHere is the original list again:”)
print(cars)
下面有一串解释
注意,在调用sorted()函数后,列表元素的排列顺序并没有变。如果要按与字母顺序相反的顺序显示列表,也可向sorted()函数传递参数reserve=True
问:如何运用书中提示来运用reserve=True,麻烦各位大神帮忙解疑答惑一下,谢谢
推荐文章: