访问列表中的信息,格式如字典Python [英] Accessing information inside a list that is formatted like a dictionary Python

查看:129
本文介绍了访问列表中的信息,格式如字典Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Twitter API向实体显示如下所示的列表:

The Twitter API spits out lists for entities that look like this:

[{'expanded_url': 'http://twitter.com/voxdotcom/status/458708072131592194/photo/1', 'display_url': 'pic.twitter.com/uc3j0nU8uf', 'url': 'http://t.co/uc3j0nU8uf', 'media_url_https': 'https://pbs.twimg.com/media/Bl2oj5_CYAAO72v.png', 'id_str': '458708071875764224', 'sizes': {'small': {'h': 256, 'resize': 'fit', 'w': 340}, 'large': {'h': 773, 'resize': 'fit', 'w': 1023}, 'medium': {'h': 453, 'resize': 'fit', 'w': 599}, 'thumb': {'h': 150, 'resize': 'crop', 'w': 150}}, 'indices': [88, 110], 'type': 'photo', 'id': 458708071875764224, 'media_url': 'http://pbs.twimg.com/media/Bl2oj5_CYAAO72v.png'}]

它看起来像一个字典,但实际上是一个列表。 Arg。

It looks like a dictionary but it is in fact a list. Arg.

如何访问特定条目?例如,如果我想要expand_url值,最好的方法是什么?

How can I access specific entries? For example, if I want the expanded_url value, what is the best way to get it?

谢谢。

*感谢您的快速回复。

*Thanks for the fast replies.

推荐答案

索引位置 0 获取字典:

>>> lst = [{'expanded_url': 'http://twitter.com/voxdotcom/status/458708072131592194/photo/1', 'display_url': 'pic.twitter.com/uc3j0nU8uf', 'url': 'http://t.co/uc3j0nU8uf', 'media_url_https': 'https://pbs.twimg.com/media/Bl2oj5_CYAAO72v.png', 'id_str': '458708071875764224', 'sizes': {'small': {'h': 256, 'resize': 'fit', 'w': 340}, 'large': {'h': 773, 'resize': 'fit', 'w': 1023}, 'medium': {'h': 453, 'resize': 'fit', 'w': 599}, 'thumb': {'h': 150, 'resize': 'crop', 'w': 150}}, 'indices': [88, 110], 'type': 'photo', 'id': 458708071875764224, 'media_url': 'http://pbs.twimg.com/media/Bl2oj5_CYAAO72v.png'}]
>>> lst[0]["expanded_url"]
'http://twitter.com/voxdotcom/status/458708072131592194/photo/1'
>>>

这篇关于访问列表中的信息,格式如字典Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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