I have the next dict:
# lists of dicts 0 (dict0)
[
{'hour': '2:00', 'key1': 1, 'key2': 501},
{'hour': '3:00', 'key1': 2, 'key2': 502},
{'hour': '4:00', 'key1': 3, 'key2': 503},
{'hour': '5:00', 'key1': 4, 'key2': 504},
]
How can I split (in a pythonic way) this list into two lists of dicts that contain {hour,key1} and {hour,key2} respectively.
# list of dicts 1 (dict1)
[
{'hour': '2:00', 'key1': 1},
{'hour': '3:00', 'key1': 2},
{'hour': '4:00', 'key1': 3},
{'hour': '5:00', 'key1': 4},
]
# list of dicts 2 (dict2)
[
{'hour': '2:00', 'key2': 501},
{'hour': '3:00', 'key2': 502},
{'hour': '4:00', 'key2': 503},
{'hour': '5:00', 'key2': 504},
]
This is what I tried so far but it guess there is another way without loops:
dict1 = []
for row in dict0:
dictionary = {'hour': row['hour'], 'key1': row['key1']}
dict1.append(dictionary)
dict2 = []
for row in dict0:
dictionary = {'hour': row['hour']),'key2': row['key2']}
dict2.append(dictionary)