Python:Dict迭代仅返回最后一个键,值对

我是Python的新手,并且已经很长时间没有编码了。感谢您的耐心配合。我知道我很可能错过了一些简单的事情……或者只是不知道解决方案。我正在使用运行conda_python3的Jupyter笔记本工作,并尝试遍历每个字典中存在的2个键,值对的多个字典。

以下是一些词典。我的目标是“ rh”和“ temp”键。

{'wind_cdir': 'WNW', 'rh': 72, 'pod': 'n', 'timestamp_utc': '2020-04-10T10:00:00', 'pres': 983.561, 'solar_rad': 0, 'ozone': 433.145, 'weather': {'icon': 'c03n', 'code': 803, 'description': 'Broken clouds'}, 'wind_gust_spd': 30.9, 'timestamp_local': '2020-04-10T06:00:00', 'snow_depth': 0, 'clouds': 55, 'ts': 1586512800, 'wind_spd': 19.1, 'pop': 0, 'wind_cdir_full': 'west-northwest', 'slp': 1006.21, 'dni': 0, 'dewpt': 23.3, 'snow': 0, 'uv': 0, 'wind_dir': 300, 'clouds_hi': 0, 'precip': 0, 'vis': 15, 'dhi': 0, 'app_temp': 22.3, 'datetime': '2020-04-10:10', 'temp': 31.3, 'ghi': 0, 'clouds_mid': 1, 'clouds_low': 55}
{'wind_cdir': 'WNW', 'rh': 68, 'pod': 'n', 'timestamp_utc': '2020-04-10T11:00:00', 'pres': 984.449, 'solar_rad': 0, 'ozone': 433.237, 'weather': {'icon': 'c02n', 'code': 801, 'description': 'Few clouds'}, 'wind_gust_spd': 32, 'timestamp_local': '2020-04-10T07:00:00', 'snow_depth': 0, 'clouds': 8, 'ts': 1586516400, 'wind_spd': 18.1, 'pop': 0, 'wind_cdir_full': 'west-northwest', 'slp': 1007.16, 'dni': 0, 'dewpt': 20.9, 'snow': 0, 'uv': 0, 'wind_dir': 300, 'clouds_hi': 0, 'precip': 0, 'vis': 15, 'dhi': 0, 'app_temp': 21.1, 'datetime': '2020-04-10:11', 'temp': 30.4, 'ghi': 0, 'clouds_mid': 0, 'clouds_low': 8}
{'wind_cdir': 'WNW', 'rh': 68, 'pod': 'd', 'timestamp_utc': '2020-04-10T12:00:00', 'pres': 985.228, 'solar_rad': 122.064, 'ozone': 431.9, 'weather': {'icon': 'c02d', 'code': 801, 'description': 'Few clouds'}, 'wind_gust_spd': 32, 'timestamp_local': '2020-04-10T08:00:00', 'snow_depth': 0, 'clouds': 6, 'ts': 1586520000, 'wind_spd': 17.8, 'pop': 0, 'wind_cdir_full': 'west-northwest', 'slp': 1007.98, 'dni': 467.54, 'dewpt': 20.9, 'snow': 0, 'uv': 1.89962, 'wind_dir': 298, 'clouds_hi': 0, 'precip': 0, 'vis': 15, 'dhi': 51.66, 'app_temp': 21, 'datetime': '2020-04-10:12', 'temp': 30.3, 'ghi': 122.07, 'clouds_mid': 1, 'clouds_low': 6}
{'wind_cdir': 'WNW', 'rh': 65, 'pod': 'd', 'timestamp_utc': '2020-04-10T13:00:00', 'pres': 985.625, 'solar_rad': 309.638, 'ozone': 430.678, 'weather': {'icon': 'c02d', 'code': 801, 'description': 'Few clouds'}, 'wind_gust_spd': 32, 'timestamp_local': '2020-04-10T09:00:00', 'snow_depth': 0, 'clouds': 12, 'ts': 1586523600, 'wind_spd': 19.6, 'pop': 0, 'wind_cdir_full': 'west-northwest', 'slp': 1008.34, 'dni': 679.6, 'dewpt': 21.1, 'snow': 0, 'uv': 2.22689, 'wind_dir': 303, 'clouds_hi': 0, 'precip': 0, 'vis': 15, 'dhi': 77.82, 'app_temp': 22.6, 'datetime': '2020-04-10:13', 'temp': 31.5, 'ghi': 309.81, 'clouds_mid': 0, 'clouds_low': 12}

这是我的代码。

for dict in data:
    for key, value in data.items():
        if key == 'rh' or key == 'temp':
            temp_dict.update({key: value})
            print(temp_dict)

结果

{'rh': 65, 'temp': 31.5}
{'rh': 65, 'temp': 31.5}
{'rh': 65, 'temp': 31.5}
{'rh': 65, 'temp': 31.5}

仅打印最后一个键,值对。

谢谢。任何帮助或指出正确方向的人都将受到赞赏。