我知道可以使用
for i in x[::-1]
来逆序遍历列表。但是如果我想跳过最后一个元素,从高到低遍历呢? for i in x[-1:0:-1]
是不起作用的。x = [1,2,3,4,5]
=> 4,3,2,1 # desired
for i in x[-1:-1]:
print(i)
# it does not work
x[-2::-1]
。 - Loocid