<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def build_grouped_ownership_map(table, key_from_row, value_from_row, group_key):
 """ Builds a dict mapping group keys to maps of keys to to lists of OwnershipPeriods, from a db table. """

    grouped_rows = groupby(
        group_key,
        sa.select(table.c).execute().fetchall(),
    )
    return {
        key: _build_ownership_map_from_rows(
            rows,
            key_from_row,
            value_from_row,
        )
        for key, rows in grouped_rows.items()
    }