Skip to content

Instantly share code, notes, and snippets.

@csaez
Created July 30, 2013 05:28
Show Gist options
  • Save csaez/6110450 to your computer and use it in GitHub Desktop.
Save csaez/6110450 to your computer and use it in GitHub Desktop.
#!/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