title: Search value in tree of dicts in python
body: <p>I have a giant dict with a lot of nested dicts -- like a giant tree, and depth in unknown.</p>
  
  <p>I need a function, something like <code>find_value()</code>, that takes <strong>dict, value (as string)</strong>, and returns <strong>list of lists</strong>, each one of them is "path" (sequential chain of keys from first key to key (or key value) with found value). If nothing found, returns empty list.</p>
  
  <p>I wrote this code:</p>
  
  <pre><code>def find_value(dict, sought_value, current_path, result):   
      for key,value in dict.items():
          current_path.pop()
          current_path.append(key)
          if sought_value in key:
              result.append(current_path)
          if type(value) == type(''):
              if sought_value in value:
                  result.append(current_path+[value])
          else:
              current_path.append(key) 
              result = find_value(value, sought_value, current_path, result)
      current_path.pop()
      return result 
  </code></pre>
  
  <p>I call this function to test:</p>
  
  <pre><code>result = find_value(self.dump, sought_value, ['START_KEY_FOR_DELETE'], [])
  if not len(result):
      print "forgive me, mylord, i'm afraid we didn't find him.."
  elif len(result) == 1:
      print "bless gods, for all that we have one match, mylord!"
  </code></pre>
  
  <p>For some inexplicable reasons, my implementation of this function fails some of my tests. I started to debug and find out, that even if <strong>current_path</strong> prints correct things (it always does, I checked!), the result is inexplicably corrupted. Maybe it is because of recursion magic?</p>
  
  <p>Can anyone help me with this problem? Maybe there is a simple solution for my tasks?</p>