Skip to content

Instantly share code, notes, and snippets.

@colobas
Created October 24, 2017 10:48
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 colobas/c0eaa9be2c2278ea4991284a254d8467 to your computer and use it in GitHub Desktop.
Save colobas/c0eaa9be2c2278ea4991284a254d8467 to your computer and use it in GitHub Desktop.
# credits to: https://stackoverflow.com/a/26209900
def pretty(value, htchar='\t', lfchar='\n', indent=0):
nlch = lfchar + htchar * (indent + 1)
if type(value) is dict:
items = [
nlch + repr(key) + ': ' + pretty(value[key], htchar, lfchar, indent + 1)
for key in value
]
return '{%s}' % (','.join(items) + lfchar + htchar * indent)
elif type(value) is list:
items = [
nlch + pretty(item, htchar, lfchar, indent + 1)
for item in value
]
return '[%s]' % (','.join(items) + lfchar + htchar * indent)
elif type(value) is tuple:
items = [
nlch + pretty(item, htchar, lfchar, indent + 1)
for item in value
]
return '(%s)' % (','.join(items) + lfchar + htchar * indent)
else:
return repr(value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment