Skip to content

Instantly share code, notes, and snippets.

@mastier
Last active December 14, 2015 01:39
Show Gist options
  • Save mastier/5007831 to your computer and use it in GitHub Desktop.
Save mastier/5007831 to your computer and use it in GitHub Desktop.
# useful way to flatten dictionary representing i.e. path to file and content
# now fixed in case of running it again
def flatten_dict(d,path=(),paths=None, sep='/'):
if paths==None: paths=[]
if isinstance(d,dict):
for k,v in d.items():
flatten_dict(v,path+(k,),paths)
return paths
else:
paths.append( { sep+sep.join(path) : d } )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment