我首先嘗試在物體串列中回圈,然后我想在 id=1 的聊天源中回圈。在 id=2 之后,它的聊天源為 1,2,3。等等。
這個結構不能解決我的問題。
entities = [
{id: 1, "chat_sources": [1, 2, 3]},
{id: 2, "chat_sources": [1, 2, 3]},
{id: 3, "chat_sources": [1, 2, 3]}
]
for i in entities:
for j in entities["chat_sources"]:
print(j)
uj5u.com熱心網友回復:
你快到了:
entities = [
{id: 1, "chat_sources": [1, 2, 3]},
{id: 2, "chat_sources": [1, 2, 3]},
{id: 3, "chat_sources": [1, 2, 3]}
]
for entity in entities: # entity is already the item rather than its index
for j in entity["chat_sources"]: # note it's entity, not entities
print(j)
uj5u.com熱心網友回復:
for elem in entities:
print(*elem['chat_sources'], sep='\n')
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/429015.html
標籤:Python python-3.x 字典 数据结构
上一篇:根據python字典的值回傳鍵
