title: Find all occurrences of a key in nested dictionaries and lists
body: <p>I have a dictionary like this:</p>
  <pre><code>{
      &quot;id&quot;: &quot;abcde&quot;,
      &quot;key1&quot;: &quot;blah&quot;,
      &quot;key2&quot;: &quot;blah blah&quot;,
      &quot;nestedlist&quot;: [
          {
              &quot;id&quot;: &quot;qwerty&quot;,
              &quot;nestednestedlist&quot;: [
                  {
                      &quot;id&quot;: &quot;xyz&quot;,
                      &quot;keyA&quot;: &quot;blah blah blah&quot;
                  },
                  {
                      &quot;id&quot;: &quot;fghi&quot;,
                      &quot;keyZ&quot;: &quot;blah blah blah&quot;
                  }
              ],
              &quot;anothernestednestedlist&quot;: [
                  {
                      &quot;id&quot;: &quot;asdf&quot;,
                      &quot;keyQ&quot;: &quot;blah blah&quot;
                  },
                  {
                      &quot;id&quot;: &quot;yuiop&quot;,
                      &quot;keyW&quot;: &quot;blah&quot;
                  }
              ]
          }
      ]
  }
  </code></pre>
  <p>Basically a dictionary with nested lists, dictionaries, and strings, of arbitrary depth.</p>
  <p>What is the best way of traversing this to extract the values of every &quot;id&quot; key? I want to achieve the equivalent of an XPath query like &quot;//id&quot;. The value of &quot;id&quot; is always a string.</p>
  <p>So from my example, the output I need is basically:</p>
  <pre><code>[&quot;abcde&quot;, &quot;qwerty&quot;, &quot;xyz&quot;, &quot;fghi&quot;, &quot;asdf&quot;, &quot;yuiop&quot;]
  </code></pre>
  <p>Order is not important.</p>