【发布时间】:2019-09-15 19:33:55
【问题描述】:
如何从列表的最后两个值中获取第一个值。
例如我有一个列表:
list1 = ['a','b','c','d','y','z']
# I know that going from 'a' to 'y' is using negatives,
n = 0 - 2
list1[n]
# This will give the value of 'y'
# but how do I do the opposite? 'y' to 'a' ?
# not fetching the values from 'y' to 'a', instead, traversing from 'y' to 'a'
【问题讨论】:
-
你的意思是
list1[-2::-1]=>['y', 'd', 'c', 'b', 'a']? -
不清楚你所说的“从
y到a”是什么意思;a可以通过list1[0]获取。
标签: python arrays python-3.x python-2.7 list