1

Print layout of a python dict, i.e. only keys and the types of the values (in ca...

 2 years ago
source link: https://gist.github.com/cmower/6b280456be76788143a4af8b6bc9f472
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Print layout of a python dict, i.e. only keys and the types of the values (in case of nested dict's an indented dict is printed). · GitHub

Instantly share code, notes, and snippets.

Print layout of a python dict, i.e. only keys and the types of the values (in case of nested dict's an indented dict is printed).

def print_dict_layout(d, indent=0): """Print layout of a dictionary. Syntax: print_dict_layout(d) Input: d [dict]: dictionary indent [int]: printing indent (no need for user to use) """ indent_spaces = " "*indent print(indent_spaces, '{') for k, v in d.items(): print(indent_spaces, "'%s'"%k, ':', end='') if isinstance(v, dict): print('') # adds \n pprint_dict(v, indent=indent+4) else: print(type(v)) print(indent_spaces, '}')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK