File size: 417 Bytes
13b5b46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b7143f3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from typing import Dict, List

def compare_programs(docs: List[dict]) -> Dict[str, Dict[str, int]]:
    matrix: Dict[str, Dict[str, int]] = {}

    for d in docs:
        agency = d.get("agency", "Unknown")
        year = d.get("date", "")[:4]

        if not year.isdigit():
            continue

        matrix.setdefault(agency, {})
        matrix[agency][year] = matrix[agency].get(year, 0) + 1

    return matrix