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
之类的东西来推进它。有没有办法通过了解当前项目的值来获取列表中的下一个项目?