Created
September 17, 2022 10:07
-
-
Save hazadus/5acbf28985a7ce69d498529070d27362 to your computer and use it in GitHub Desktop.
Pretty print nested list/dicts
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 print_collection(collection, tab): | |
if type(collection) == dict: | |
for key in collection: | |
print(f'{tab}"{key}": "{collection[key]}"') | |
if type(collection[key]) in (list, dict): | |
print(tab + '{') | |
print_collection(collection[key], tab + '\t') | |
print(tab + '}') | |
elif type(collection) == list: | |
for item in collection: | |
print(f'{tab}List item - [') | |
if type(item) in (list, dict): | |
print_collection(item, tab + '\t') | |
print(f"{tab}]") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment