python - #python 从列表中提取信息
问题描述
这是我的代码:
for item in data ["items"]:
for p in item ["standings"]["clan"]["participants"]:
print("%s %s" % (
p["tag"],
p["name"],
))
出现此错误:
File "_players_.py", line 26, in <module>
for p in item ["standings"]["clan"]["participants"]:
TypeError: list indices must be integers or slices, not str
请问有什么帮助吗?
谢谢
解决方案
查看您的图片,会item["standings"]
产生一个列表,而不是字典。这将通过错误来确认,该错误详细说明了使用字符串对列表进行索引。所以,我假设你会想要一些类似的东西:
...
for s in item["standings"]:
for p in s["clan"]["participants"]:
...
推荐阅读
- node.js - 如何在 node js 中将 app.post 和 app.get 合二为一
- sql-server - 我如何从列现有值的表中获取数据
- mongodb - 如何将相同的文档存储在多个集合中
- pyautogui - 使用 pyautogui 时应用程序如何获得鼠标移动
- php - laravel 基于 API 响应调用的自定义认证
- ms-word - 是否有 dart 包来解码 ms word 文档并在颤振应用程序中进行编辑?
- mysql - 在 Codeigniter 中使用查询生成器 - 如何正确别名?
- google-cloud-platform - 使用 Google Cloud Datastore GQL 编辑器时,我可以在 GQL 中使用注释吗?
- angular - 使用 Angular 4+ 在组件内注入任何 html/ 组件
- android-recyclerview - 在滚动时在 recyclerview 中加载更多数据