Question: I know this is a frequently asked question, however I do not have access to the Counter module as I'm using v2.6 of Python. I want to count the number of time a specific key appears in a list of dictionaries.

If my dictionary looks like this:

```
data = [{'a':1, 'b':1}, {'a':1, 'c':1}, {'b':1, 'c':1}, {'a':1, 'c':1}, {'a':1, 'd':1}]

```

How would I find out how many times "a" appears? I've tried using len, but that only returns the number of values for one key.

```
len(data['a'])

```

Answer: 
You won't have access to **`collections.Counter`**, but **`collections.defaultdict`** was added in Python 2.5

**`keys`** and flatten list

```
data = [j for i in data for j in i.keys()]

# ['a', 'b', 'a', 'c', 'c', 'b', 'a', 'c', 'a', 'd']

```

**`collections.defaultdict`**

```
from collections import defaultdict
dct = defaultdict(int)

for key in data:
  dct[key] += 1

# defaultdict(<type 'int'>, {'a': 4, 'c': 3, 'b': 2, 'd': 1})

```

If you only need the count for `a`, there are simpler ways to do this, but this will give you the counts of all keys in your list of dictionaries.
For this you could write the following function that would work for data in the structure you provided (a list of dicts):

```
def count_key(key,dict_list):
    keys_list = []
    for item in dict_list:
        keys_list += item.keys()
    return keys_list.count(key)

```

Then, you could invoke the function as follows:

```
data = [{'a':1, 'b':1}, {'a':1, 'c':1}, {'b':1, 'c':1}, {'a':1, 'c':1}, {'a':1, 'd':1}]
count_a = count_key('a',data)

```

In this case, count\_a will be 4.