def dict_format_type(d, source, formatter, include_list=True):
if not isinstance(d, dict):<EOL><INDENT>if isinstance(d, source):<EOL><INDENT>return formatter(d)<EOL><DEDENT>else:<EOL><INDENT>return d<EOL><DEDENT><DEDENT>else:<EOL><INDENT>dd = dict()<EOL>for key, value in d.items():<EOL><INDENT>if include_list and isinstance(value, list):<EOL><INDENT>dd[key] = [dict_format_type(i, source, formatter) for i in value]<EOL><DEDENT>elif isinstance(value, dict):<EOL><INDENT>dd[key] = dict_format_type(value, source, formatter)<EOL><DEDENT>elif isinstance(value, source):<EOL><INDENT>dd[key] = formatter(value)<EOL><DEDENT>else:<EOL><INDENT>dd[key] = value<EOL><DEDENT><DEDENT>return dd<EOL><DEDENT>
Replace the values of a dict with certain type to other values
:param d: the dictionary
:param source: the source type, e.g., int
:param formatter: the formatter method, e.g., return the string format of an int
:param include_list: whether list should be formatted, otherwise list will be considered as source type
:return: formatted dictionary