-1
鉴于其性质,OrderedDict
中的项目是有序的,人们可能会认为它具有类似于列表的index
函数的功能。它不是。OrderedDict的list.index()的等价物?
对于OrderedDict
,模仿index
的最Pythonic/neatest方法是什么?
鉴于其性质,OrderedDict
中的项目是有序的,人们可能会认为它具有类似于列表的index
函数的功能。它不是。OrderedDict的list.index()的等价物?
对于OrderedDict
,模仿index
的最Pythonic/neatest方法是什么?
这取决于你想要的index
的。 如果你想有一个关键的指标,你可以做
o = OrderedDict([('toast',5.80),('waffles',2.30),('pancakes',3.99)])
print o.keys().index('waffles')
我需要的正是。 – Pyderman
http://stackoverflow.com/a/27726326/742269 –