[英]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.