def materialize(reference_dict, source):
materialized_dict = {}<EOL>for field in reference_dict:<EOL><INDENT>reference = reference_dict[field]<EOL>if isinstance(reference, list):<EOL><INDENT>materialized_dict[field] = [source[index] for index in reference]<EOL><DEDENT>elif reference is not None:<EOL><INDENT>materialized_dict[field] = source[reference]<EOL><DEDENT>else:<EOL><INDENT>materialized_dict[field] = None<EOL><DEDENT><DEDENT>return materialized_dict<EOL>
Replace indices by actual elements in a reference mapping
:param reference_dict: mapping str -> int | int[]
:param source: list of elements
:return: mapping str -> element | element[]