Created
February 13, 2019 13:16
-
-
Save aasmpro/1cff0b4be03677238d9fac320dfe56d7 to your computer and use it in GitHub Desktop.
python simple prettify
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
def prettify(data, indent=' ', indent_num=0): | |
result = '' | |
if isinstance(data, list) or isinstance(data, tuple): | |
for i in data: | |
if isinstance(i, list) or isinstance(i, tuple) or isinstance(i, dict): | |
result += "{}".format(prettify(i, indent, indent_num)) | |
else: | |
result += indent * indent_num + "{}\n".format(str(i)) | |
elif isinstance(data, dict): | |
for k, v in data.items(): | |
if isinstance(v, list) or isinstance(v, tuple) or isinstance(v, dict): | |
result += indent * indent_num + "{}:\n{}".format(k, prettify(v, indent, indent_num + 1)) | |
else: | |
result += indent * indent_num + "{}: {}\n".format(k, str(v)) | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
input
output