title: How to get values from a list of dictionaries, which themselves contain lists of dictionaries in Python
body: <p>I encountered the problem of getting values from a list that contains dictionaries, where each of the dictionaries has a list with a dictionary. May sound easy to do but it took me some time and I think it can be useful for other people if I post it. An example of my data can be:</p>
  <blockquote>
  <pre><code>player_info = [{[{'tag': 'tag 1'}]},
                 {[{'tag': 'tag 2'}]}]
  </code></pre>
  </blockquote>
  <p>The outer list is called 'player_info'. This contained 25 dictionaries, where each one contains a list that contains (among other things) a dictionary called 'opponent' which contains a list that contains a dictionary (yeah, pretty messy). From that innermost dictionary, I wanted the value associated with the 'tag' key.</p>
  <p>I figured two ways:</p>
  <ol>
  <li>Create a loop.</li>
  </ol>
  <blockquote>
  <pre><code>for i in range(25):
      print(player_info[i]['opponent'][0]['tag'])
  </code></pre>
  </blockquote>
  <ol start="2">
  <li>Iterate through list:</li>
  </ol>
  <blockquote>
  <pre><code>{each_dictionary['opponent'][0]['tag'] for each_dictionary in player_info}
  </code></pre>
  </blockquote>
  <p>I assume that the second way must be more efficient. Let me know what you think, and whether there is a smarter way to do it.</p>