通过python中的索引访问字典值 [英] Accessing dictionary value by index in python

查看:505
本文介绍了通过python中的索引访问字典值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆