gpt4 book ai didi

python - 如何访问Python字典

转载 作者:行者123 更新时间:2023-12-01 00:09:05 25 4
gpt4 key购买 nike

如果我执行print(response["response"]),我会得到下面的代码,但我只想打印"currency_code"的每个值,我需要什么做什么?

{
"account_id": "2b9e9aea-59e4-11e9-8c75-0a0e6623f374",
"balances": [
{
"account_id": "2b9e9aea-59e4-11e9-8c75-0a0e6623f374",
"currency_code": "FEST",
"change": "0.0",
"available": "350.55778445",
"locked": "0.0",
"sequence": 8256,
"time": "2020-01-15T17:35:04.435Z"
},
{
"account_id": "2b9e9aea-59e4-11e9-8c75-0a0e6623f374",
"currency_code": "BTC",
"change": "0.0",
"available": "0.000002444748",
"locked": "0.0",
"sequence": 8241,
"time": "2020-01-14T23:30:12.570Z"
},
{
"account_id": "2b9e9aea-59e4-11e9-8c75-0a0e6623f374",
"currency_code": "ETH",
"change": "0.3118",
"available": "0.0",
"locked": "0.0",
"sequence": 8015,
"time": "2020-01-13T06:59:06.443Z"
},
{
"account_id": "2b9e9aea-59e4-11e9-8c75-0a0e6623f374",
"currency_code": "EUR",
"change": "35.96096",
"available": "49.63897609",
"locked": "0.0",
"sequence": 8256,
"time": "2020-01-15T17:35:04.435Z"
},
{
"account_id": "2b9e9aea-59e4-11e9-8c75-0a0e6623f374",
"currency_code": "MIOTA",
"change": "15802.0",
"available": "0.0",
"locked": "0.0",
"sequence": 8214,
"time": "2020-01-14T23:00:11.357Z"
},
{
"account_id": "2b9e9aea-59e4-11e9-8c75-0a0e6623f374",
"currency_code": "BAN",
"change": "1106.0",
"available": "0.06758229",
"locked": "0.0",
"sequence": 7986,
"time": "2020-01-08T11:53:27.266Z"
},
{
"account_id": "2b9e9aea-59e4-11e9-8c75-0a0e6623f374",
"currency_code": "XRP",
"change": "14157.0",
"available": "0.0",
"locked": "0.0",
"sequence": 8238,
"time": "2020-01-14T23:30:07.002Z"
}
]
}

最佳答案

您需要从嵌套字典中取出每个元素,然后迭代字典列表并打印货币代码:

for bal in response.get('response').get('balances'):
print(bal.get('currency_code', ''))

关于python - 如何访问Python字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59759878/

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