我有这样的清单:
[{"id": 101, "name": "music1"}, {"id": 102, "name": "music2"}]
如何获取与特定名称匹配的对象ID:
例如,
input: music2
output : 102
答案 0 :(得分:1)
a = [{"id": 101, "name": "music1"}, {"id": 102, "name": "music2"}]
input = "music2"
for i in a:
if i["name"] == input:
print(i["id"])