data = [['A', 'B', 'C', 'D'],
['E', 'F', 'G'],
['I', 'J'],
['A', 'B', 'C', 'E', 'F']]
I would like to remove unpopular elements (appearing only once) from the lists. So the results should look like this:
data = [['A', 'B', 'C'],
['E', 'F'],
['A', 'B', 'C', 'E', 'F']]
I was able to count the frequency of each element using the following codes:
from collections import Counter
Counter(x for sublist in data for x in sublist)
#output
Counter({'A': 2, 'C': 2, 'B': 2, 'E': 2, 'F': 2, 'D': 1, 'G': 1, 'I': 1, 'J': 1})
However, I am not sure how to use this count information to remove unpopular elements from the list. Any help?