Skip to content

Instantly share code, notes, and snippets.

@corburn
Created May 17, 2014 19:43
Show Gist options
  • Save corburn/e872bae66072aab691d6 to your computer and use it in GitHub Desktop.
Save corburn/e872bae66072aab691d6 to your computer and use it in GitHub Desktop.
Recursively pretty print types of complex python structure
def print_type(data, indent_level):
if type(data) == dict:
for key in data:
print '\t' * indent_level + str(key) + ' ' + str(type(data[key]))
print_types(data[key], indent_level+1)
elif type(data) == list:
for i in range(len(data)):
print '\t' * indent_level + str(i) + ' ' + str(type(data[i]))
print_types(data[i], indent_level+1)
@lallulli
Copy link

Sweet.
The name of the function should be print_types (plural), otherwise recursion won't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment