my_list = ['apple', 'pear', 'orange', 'raspberry']
# I know that I'm always looking for pear.
print 'pear' in my_list # prints True
# I want to be able to get a key by its value.
pear_key = my_list['pear'].key # should be 1
# Print the next item in the list.
print my_list[pear_key + 1] # should print orange
我知道pear
將永遠是我列表中的一個項目(不是位置雖然),我正在尋找一種方法來獲取該列表中的下一個項目的值,或者通過獲取當前的鍵通過知道它的價值並且通過一個(像我在上面的例子中那樣)或者通過使用諸如my_list.next
之類的東西來推進它。有沒有辦法通過了解當前項目的值來獲取列表中的下一個項目?