× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

How to check keys in two levels loop?

Cristian Lupașcu
Mar 04, 2015
<p>Assuming you hold the data in a dictionary called <code>data</code>, you could write the following code that uses a <a href="https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehension</a>:</p> <pre><code>print len([key for key in data if data[key]['poi']]) </code></pre> <p>to display the number of items that have the <code>'poi'</code> attribute set to <code>True</code>.</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/28848786/How%20to%20check%20keys%20in%20two%20levels%20loop?/28848969">Stack Overflow</a>.</p>
comments powered by Disqus