import re
from pathlib import Path


def build_dir_year_dict(dirs):
    """Returns a dict with path as the key and 4-digit year as the value."""

    yr_reg = re.compile(r"\d{4}")
    hits = [yr_reg.search(str(dir)) for dir in dirs]
    return {Path(_match.string): _match.group() for _match in hits if _match}