recursion - Python: file search using dictionary -


i have written small script find file in directories , sub-directories. placed these in dictionaries , sub dictionaries within root dictionary.

so trying find file within dictionary of files , sub directories. trying print out contents of dictionary first able modify code file within dictionary.

here code:

def recurdd(db):     key in db:         item in db[key]:             if hasattr(item,'append'):                 recurdd(item)             else:                 print key,'=>',db[key]                 print 

this code prints out same dictionary time want correct. if have dictionary, i.e.:

d = {'a': [{'b': [1, 2, 3]}, {'c': [55, 12, 32]}, 1, 2]} 

please assist me issue.

thanks

the correct code be:

def recurse_directory(dictionary):     dirname, dir_content in dictionary.iteritems():         filename in dir_content:             if type(filename) == dict: # it's directory                 recurse_directory(filename)             else:                 print "{} => {}".format(dirname, filename) 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -