from typing import List, Tuple, TypeVar, Dict MapDbValueType = TypeVar('MapDbValueType') def map_db_result_with_column_names(raw_db_result: List[Tuple[MapDbValueType]], column_names: Tuple[str, ...]) -> List[Dict[str, MapDbValueType]]: """Map raw db result that we get from snowflake as List of objects with values only with provided column names The provided Tuple of column names should reflect the column names from sql query. Args: raw_db_result: Raw query result column_names: Tuple of column names the result will be mapped Returns: List of Dict objects where column name mapped to result it represents """ # Map the result that is a List[Tuple[...] for every row] to get a List[Dict[...] for every row] # with keys from column_names and values from DB return [{c: v for c, v in zip(column_names, row)} for row in raw_db_result]