gpt4 book ai didi

python - 在检查符号为 BTC 后,我想访问美元下的价格值

转载 作者:太空宇宙 更新时间:2023-11-03 20:39:59 25 4
gpt4 key购买 nike

我正在尝试访问中间包含列表的嵌套字典

r={
"status": {
"timestamp": "2019-07-07T09:26:17.112Z",
"error_code": 0,
"error_message": null,
"elapsed": 11,
"credit_count": 1
},
"data": [
{
"id": 1,
"name": "Bitcoin",
"symbol": "BTC",
"slug": "bitcoin",
"circulating_supply": 17803762,
"total_supply": 17803762,
"max_supply": 21000000,
"date_added": "2013-04-28T00:00:00.000Z",
"num_market_pairs": 7658,
"tags": [
"mineable"
],
"platform": null,
"cmc_rank": 1,
"last_updated": "2019-07-07T09:25:27.000Z",
"quote": {
"USD": {
"price": 11209.5138577,
"volume_24h": 18924903576.9248,
"percent_change_1h": 0.12998,
"percent_change_24h": -1.4482,
"percent_change_7d": -4.43763,
"market_cap": 199571516858.19266,
"last_updated": "2019-07-07T09:25:27.000Z"
}
}
},
{
"id": 1027,
"name": "Ethereum",
"symbol": "ETH",
"slug": "ethereum",
"circulating_supply": 106797544.1866,
"total_supply": 106797544.1866,
"max_supply": null,
"date_added": "2015-08-07T00:00:00.000Z",
"num_market_pairs": 5422,
"tags": [
"mineable"
],
"platform": null,
"cmc_rank": 2,
"last_updated": "2019-07-07T09:25:19.000Z",
"quote": {
"USD": {
"price": 287.981264275,
"volume_24h": 7137227743.75008,
"percent_change_1h": -0.10015,
"percent_change_24h": -1.14435,
"percent_change_7d": -6.76952,
"market_cap": 30755691796.322243,
"last_updated": "2019-07-07T09:25:19.000Z"
}
}
},

在检查符号为 BTC 后,我尝试访问美元字典中的价格

最佳答案

Python 不支持 null(例如"platform": null,),它应该放在双引号内或尝试 None

for row in r['data']:
if row['symbol'] in 'BTC':
print(row['quote']['USD']['price'])

操作:

11209.5138577
..

关于python - 在检查符号为 BTC 后,我想访问美元下的价格值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56921869/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com