Skip to content

Instantly share code, notes, and snippets.

@arne-cl
Created September 19, 2015 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arne-cl/a171ee6cdc9d6ddedc0c to your computer and use it in GitHub Desktop.
Save arne-cl/a171ee6cdc9d6ddedc0c to your computer and use it in GitHub Desktop.
prettyprint a nested dictionary
def nprint(d, tab=0, tab_width=2):
'''print nested key-value datastructures (e.g. dicts)'''
for k, v in d.iteritems():
if not hasattr(v, 'iteritems'):
print u'{}{} {}'.format(' '*tab, k, v)
else:
print u'{}{}:'.format(' '*tab, k)
nprint(v, tab=tab+tab_width)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment