Python Query properties of dict by value
<p>I'm trying to get the count of properties in a dict where poi == true. I've included a C# example for reference, followed by my python code. </p>

<p>What's the correct way of doing this in Python?</p>

<p>C#:</p>

<pre><code>enron_data.where(x =&gt; x.poi == true).count()
</code></pre>

<p>In Python:</p>

<pre><code>i = 0
for key,value in enron_data.items():
    if value["poi"]:
        i = i + 1
print i
</code></pre>

<p>enron_data Sample:</p>

<pre><code>{'METTS MARK': {'salary': 365788, 'to_messages': 807, 'deferral_payments': 'NaN', 'total_payments': 1061827, 'exercised_stock_options': 'NaN', 'bonus': 600000, 'restricted_stock': 585062, 'shared_receipt_with_poi': 702, 'restricted_stock_deferred': 'NaN', 'total_stock_value': 585062, 'expenses': 94299, 'loan_advances': 'NaN', 'from_messages': 29, 'other': 1740, 'from_this_person_to_poi': 1, 'poi': False, 'director_fees': 'NaN', 'deferred_income': 'NaN', 'long_term_incentive': 'NaN', 'email_address': 'mark.metts@enron.com', 'from_poi_to_this_person': 38}}
</code></pre>

<p>You could use the <code>iter_items()</code> function like so:</p>

<pre><code>i = 0
for key,value in enron_data.iter_items():
    if value["poi"]:
        i = i + 1
print i
</code></pre>

<p>OR</p>

<pre><code>i = 0
for key,value in enron_data.iter_items():
    i += int(value["poi"])
print i
</code></pre>

python