Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # recursive search and replace
- # pass an empty string intialally with item_map
- # pass epty dict into result_dict
- def recurse(data, pat, item_map, result_dict):
- if isinstance(data, dict):
- for key in data:
- if data[key] == pat:
- # when you get down prep it
- cur_path = item_path + '.'+key
- for task_obj in enumerate(data):
- key_name = task_obj[1]
- if data[key] == pat:
- data[key] = input("Input a dict value: ")
- # set in here so you can use it later in program with "fully qualified string key"
- result_dict[cur_path] = data[key]
- else:
- # prep for going deeper
- item_map += '.'+key
- # and pass through
- recurse(data[key], pat, item_map, result_dict)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement