通过python中的索引访问字典值 [英] Accessing dictionary value by index in python
问题描述
dic = {}
value_at_index = dic.ElementAt )
其中 index
是一个整数
PS问问题意味着缺乏一些理解,特别是如果它是一种新的语言,那么下降是什么,伙计? (
ElementAt
广泛应用于C#Linq
标准Python字典本来就是无序的,所以你要求做的并不真实。
如果你真的知道你在做什么,使用
value_at_index = dic.values()[index]
请记住,添加或删除元素可能会改变每个其他元素的索引。
I would like to get the value by key index from a Python dictionary. Is there a way to get it something like this?
dic = {}
value_at_index = dic.ElementAt(index)
where index
is an integer
P.S. Asking question means lack of some understanding especially if it's a new language, so what the downvoting is for, buddies? :(
ElementAt
is widely used in C# Linq
Standard Python dictionaries are inherently unordered, so what you're asking to do doesn't really make sense.
If you really, really know what you're doing, use
value_at_index = dic.values()[index]
Bear in mind that adding or removing an element can potentially change the index of every other element.
这篇关于通过python中的索引访问字典值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!