Python - Group by over dicts
<p>I am using Python 3.5 and I have the following array of dics:</p>

<pre><code>d1 = [{id=1, col="name", oldvalue="foo", newvalue="bar"}, {id=1, col="age", oldvalue="25", newvalue="26"}, {id=2, col="name", oldvalue="foo", newvalue="foobar"}, {id=3, col="age", oldvalue="25", newvalue="26"}]

d2 = [{id=1, col="name", oldvalue="foo", newvalue="bar"}, {id=1, col="age", oldvalue="25"]

d3 = [{id=3, col="age", oldvalue="25", newvalue="26"}]
</code></pre>

<p>As you can see it is showing some changes made to particular "rows".</p>

<p>I want to know if there is a way to return the total of rows updated, so:</p>

<pre><code>def counting_updates(d):
    # ...
    return total

print counting_updates(d1) # prints 3 because 3 rows were updated
print counting_updates(d2) # prints 1 because 1 row was updated
print counting_updates(d3) # prints 1 because 1 row was updated
</code></pre>

<p>If you're looking for the number of unique <code>id</code>s, then</p>

<pre><code>len({row['id'] for row in d})
</code></pre>

<p>The <code>{}</code> is a set comprehension.</p>

python dictionary python-3.5