Question: Say I have the following list:

```
result = [{"name": "a", "number": 1},
{"name": "a", "number": 2},
{"name": "b", "number": 1},
{"name": "a", "number": 1}]

```

Can I turn it into something like:

```
result = [{"name": "a", "number": 1, "count": 2},
{"name": "a", "number": 2},
{"name": "b", "number": 1}]

```

I tried using the Count class but I couldn't make it work with dictionaries.

Answer: 
You can use `collections.Counter` with list comprehension:

```
from collections import Counter
[dict(tuple(t) + (('count', c),)) for t, c in Counter(frozenset(d.items()) for d in result).items()]

```

This returns:

```
[{'number': 1, 'name': 'a', 'count': 2}, {'number': 2, 'name': 'a', 'count': 1}, {'number': 1, 'name': 'b', 'count': 1}]

```
The `Counter` class relies on your objects being hashable to count them. Thus, a work-around could be to cast your dictionaries to their immutable equivalents.

The immutable equivalent of a `dict` is a `frozenset` (to account for unorderness of `dict`) of `tuple`. 

You can then count then and form back a list of dictionaries from the counter. 

```
from collections import Counter

result = [{"name": "a", "number": 1},
    {"name": "a", "number": 2},
    {"name": "b", "number": 1},
    {"name": "a", "number": 1}]

frozen_result = map(lambda d: frozenset(d.items()), result)

count = Counter(frozen_result)

new_result = [dict(k, count=v) for k, v in count.items()]

print(new_result)

```

Output
------

```
[{'number': 1, 'name': 'a', 'count': 2},
 {'number': 2, 'name': 'a', 'count': 1},
 {'name': 'b', 'number': 1, 'count': 1}]

```