Question: My data are in lists.

```
data = [['Biz_Innovations', '#socialmedia'],
 ['ChantalGrange', '#aws'],
 ['beyonddevops', '#aws'],
 ['beyonddevops', '#socialmedia'],
 ['IBMNetezza', '#ibm'],
 ['IBMNetezza', '#analytics'],
 ['SandraFeinsmith', '#ibm'],
 ['SandraFeinsmith', '#analytics'],
 ['fleejack', '#healhcare'],
 ['bigdataweek', '#socialmedia'],
 ['sabumjung', '#aws']]

```

I would like to count the frequency of words in the second column (e.g., #socialmedia, #aws) and then select the rows based on the that frequency. If the word appears three times or more in the dataset, I would like to keep the respective rows (and other rows are dropped). So the results would look like this:

```
data = [['Biz_Innovations', '#socialmedia'],
 ['ChantalGrange', '#aws'],
 ['beyonddevops', '#aws'],
 ['beyonddevops', '#socialmedia'],
 ['bigdataweek', '#socialmedia'],
 ['sabumjung', '#aws']]

```

Any suggestions?

Answer: 
```
>>> import collections, operator
>>> words = collections.Counter(map(operator.itemgetter(1), data))
>>> populars = [p for p in data if words[p[1]] >= 3]

```
You could use `collections.Counter` for this:

```
import collections
counts = collections.Counter(tag for (_, tag) in data)
data = [[val, tag] for (val, tag) in data if counts[tag] >= 3]

```