等同于 OrderedDict 的 list.index()?

Equivalent of list.index() for an OrderedDict?

鉴于其本质,OrderedDict 中的项目是有序的,人们可能期望它具有类似于列表的 index 功能的功能。它没有。

OrderedDict 模仿 index 的最 Pythonic/最简洁的方法是什么?

这取决于你想要什么index。 如果你想要一个键的索引,你可以这样做

o = OrderedDict([('toast',5.80),('waffles',2.30),('pancakes',3.99)])
print o.keys().index('waffles')