Python 两个名称相同但值不同的键

Python 两个名称相同但值不同的键,python,dictionary,Python,Dictionary,我正在编写一个程序,提示用户输入位置、联系web服务并检索json。然后需要解析数据并检索 第一个“place_id”键。现在饼干都碎了。有两个键具有相同的名称“place_id”,但值不同。由于索引不适用于字典,解决方案是什么 items=js['results'] for items in js['results']: placeid['place_id']=items['place_id'] print(placeid) 我希望输出是 {'place_id': 'ChIJ

我正在编写一个程序,提示用户输入位置、联系web服务并检索json。然后需要解析数据并检索 第一个“place_id”键。现在饼干都碎了。有两个键具有相同的名称“place_id”,但值不同。由于索引不适用于字典,解决方案是什么

items=js['results']
for items in js['results']:
    placeid['place_id']=items['place_id']
    print(placeid)
我希望输出是

{'place_id': 'ChIJVUqIm-fP20YRj5roNMigAqg'}
但是我越来越

{'place_id': 'ChIJVUqIm-fP20YRj5roNMigAqg'}
{'place_id': 'ChIJs4tH49_P20YRMW0pE5A376M'}

如果可以通过键更新值,请使用此键:

dict.update({'key1': 'value1'})

如果你只想要第一个,当你发现一些东西时,就加上一个休息