-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessor.py
More file actions
41 lines (31 loc) · 984 Bytes
/
Copy pathprocessor.py
File metadata and controls
41 lines (31 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from typing import List, Dict
def process_data(data: List[Dict[str, int]]) -> Dict[str, int]:
"""
Processes a list of dictionaries containing numeric data.
Args:
data (List[Dict[str, int]]): A list of dictionaries where each dictionary contains
string keys and integer values.
Returns:
Dict[str, int]: A dictionary with summed values for each key.
"""
result: Dict[str, int] = {}
for entry in data:
for key, value in entry.items():
if key in result:
result[key] += value
else:
result[key] = value
return result
def main() -> None:
"""
Main function to demonstrate data processing.
"""
sample_data: List[Dict[str, int]] = [
{'a': 1, 'b': 2},
{'a': 3, 'c': 4},
{'b': 5, 'c': 6}
]
processed = process_data(sample_data)
print(processed)
if __name__ == '__main__':
main()