回答編集履歴

2

2023/02/24 11:20

投稿

melian
melian

スコア19825

test CHANGED
@@ -5,7 +5,7 @@
5
5
  data = response.json()
6
6
  weather_data = {t: dict(zip(['天気', '風速', '風向'], d)) for t, *d in zip(*data['hourly'].values())}
7
7
 
8
- print(weather_data.get('2023-02-24T20:00'))
8
+ print(weather_data.get('2023-02-24T20:00', None))
9
9
 
10
10
  # {'天気': 0, '風速': 6.6, '風向': 9}
11
11
  ```

1

2023/02/24 11:20

投稿

melian
melian

スコア19825

test CHANGED
@@ -3,15 +3,9 @@
3
3
  ```python
4
4
  #レスポンス
5
5
  data = response.json()
6
- weathercode = data['hourly']['weathercode']
6
+ weather_data = {t: dict(zip(['天気', '風速', '風向'], d)) for t, *d in zip(*data['hourly'].values())}
7
- windspeed = data['hourly']['windspeed_10m']
8
- winddirection = data['hourly']['winddirection_10m']
9
7
 
10
- print(weathercode)
8
+ print(weather_data.get('2023-02-24T20:00'))
11
- print(windspeed)
12
- print(winddirection)
13
9
 
14
- # [1, 1, 1, 2, 3, 3, 2, 2, 51, 51, ...
15
- # [7.0, 5.9, 3.4, 5.3, 4.6, 4.6, 4.1, 4.3, 3.1, 2.2, ...
10
+ # {'天気': 0, '風速': 6.6, '風向': 9}
16
- # [21, 11, 58, 62, 72, 39, 38, 42, 21, 9, ...
17
11
  ```