python - 从json文件中提取信息,然后使用python排序
问题描述
基本上我想获得排名前 10 位的加密货币名称。每种加密货币在给定的 json 屏幕截图中都有其排名。无论如何我可以在python中实现这个吗?
提供指向所显示图像的链接 https://api.nomics.com/v1/currencies/ticker?key=demo-26240835858194712a4f8cc0dc635c7a
解决方案
尝试这个:
import json
# your saved json response from API
file_path = "full/path/to/file.json"
with open(file_path, "r") as f:
data = json.load(f)
top_10_names = [x["name"] for x in data[:10]]
# since the data is ordered by rank,
# you can take only the first 10 elements.
print(top_10_names)
推荐阅读
- spring-boot - 在同一个项目中集成 eureka 和 SBA
- flutter - 导航到不同屏幕时如何使用 PageTransitionsBuilder?
- html - 使用 R 更快地抓取网页
- node.js - 将 API 响应与自身进行比较
- c# - Windows 窗体程序集
- sql - 如何从 1 个表中选择多行并插入到另一个表中特定行的特定 JSONB 字段中?但在单个原始 SQL 查询中
- python - 尝试区分按钮,因为两个按钮有一个类名
- python - 如何高效构建句子级倒排索引?
- verilog - bluespec编译的文件头
- google-cloud-platform - 通过 Node-RED 对 http 请求进行 Google Bearer 身份验证