python OrderedDict 获取关键索引的

标签 python python-3.x list ordereddictionary

OrderedDict 能否获得关键位置?

类似于 index()list

test = ['a', 'b', 'c', 'd', 'e']
test.index('b') # return 1

最佳答案

只有一行程序。 比如:

print(list(your_ordered_dict).index('your_key'))

也许你可以使用lambda,像这样一行程序:

f = lambda ordered_dict, key: list(ordered_dict).index(key)

祝你好运。

关于python OrderedDict 获取关键索引的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49642873/

相关文章:

python - 在 Python 中对二维列表进行排序

python - 从一个条件到另一个条件选择数据框行

python - Django 模板中突出显示的帖子

python - 从列表 Python 3.3.4 中获取具有最高整数的变量名称

java - 在 Java 中使用传递子类数组作为它们的父类

python - 用 h2 标签替换 <strong> 标签

python - ULN2003驱动器的步进电机只振动不转动

python - 写入在第二个函数中打开的文件 (Python)

python - 如何查找这个词典文件呢?

python - 不确定如何取消长时间运行的异步任务