Created
May 17, 2014 19:43
-
-
Save corburn/e872bae66072aab691d6 to your computer and use it in GitHub Desktop.
Recursively pretty print types of complex python structure
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_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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sweet.
The name of the function should be print_types (plural), otherwise recursion won't work.