简体   繁体   English

如何在 python 字典中的特定索引处获取密钥?

[英]How do i get the key at a specific index in a python dictionary?

So i need a function to delete a key at a specific index.所以我需要一个 function 来删除特定索引处的键。 Is there a built-in function which does that, or do i have to do it on my own?是否有内置的 function 可以做到这一点,还是我必须自己做?

Example:例子:

my_dict={"bus":"2$","uber":"5$","taxi":"5$"}

var1 = my_dict.function(0)
var2 = my_dict.function(2)
var3 = my_dict.function(1)

In this case, var1 would be "bus", var2 would be "taxi" and var3 would be "uber".在这种情况下,var1 是“bus”,var2 是“taxi”,var3 是“uber”。

You can turn all the keys into a list then index based on that.您可以将所有键转换为列表,然后根据该列表进行索引。

my_dict={"bus":"2$","uber":"5$","taxi":"5$"}
var1 = list(my_dict.keys())[0]

out出去

bus

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python:字典键作为行索引,值作为列标题。 如何使用字典引用并选择 df 中的特定值? - python: Dictionary key as row index, values as column headers. How do I refer back and select specific values in a df using a dictionary? 如何在Python中为特定键创建列表作为字典条目? - How do I create a list as a dictionary entry for a specific key in Python? 我如何从 python 字典中获取特定的元素和键 - How can i get specific Element and key from python Dictionary 如何在索引 python 中获取字典键 - how to get dictionary key inside index python 如果特定键项在字典中,如何获取列表中字典的索引 - How to get the index of a dictionary inside list if a specific key item is in the dictionary Python-获取元组字典中特定元组索引最小值的键 - Python - Get key of specific tuple index minimum in dictionary of tuples 如何获得python字典中的最高键? - How do I get the highest key in a python dictionary? 如何将键转换为值并将索引作为字典中的键? - How do I shift key into values and make index as key in dictionary? 如何从每个键有多个值的字典中的键中获取特定值? - How do I get a specific value from a key in a dictionary with multiple values per key? 在 Nuke 中,如何使用 python 获取特定用户旋钮的索引? - In Nuke, how do I get the index of a specific user knob with python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM