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
Post a Comment