Created
July 30, 2013 05:28
-
-
Save csaez/6110450 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
mydict = {"root": {"dir1": {"subdir1": "foo"}, | |
"dir2": {"subdir2": "bar", | |
"subdir3": {"subdir4": {"subdir5": "baz", | |
"subdir6": "foo_again"}}}}} | |
def get_contents(directories): | |
results = list() | |
for k, v in directories.iteritems(): | |
if type(v) == dict: | |
v = get_contents(v) | |
results.extend(v) | |
else: | |
results.append(v) | |
return results | |
print get_contents(mydict) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment