Skip to content

Instantly share code, notes, and snippets.

@hazadus
Created September 17, 2022 10:07
Show Gist options
  • Save hazadus/5acbf28985a7ce69d498529070d27362 to your computer and use it in GitHub Desktop.
Save hazadus/5acbf28985a7ce69d498529070d27362 to your computer and use it in GitHub Desktop.
Pretty print nested list/dicts
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