Created
October 24, 2017 10:48
-
-
Save colobas/c0eaa9be2c2278ea4991284a254d8467 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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