Reputation: 901
I have many Python lists filled with words and among those words I would like to keep the ones who appears in at least two lists.
My first guess was to collapse all those list into a big one and then to keep the words who have a count > 1.
The problem is that I have some memory issue when I try to collapse all the list into a big one.
Any help please ? thanks a lot
Upvotes: 0
Views: 49
Reputation: 25954
If you're counting things, use a counter!
from collections import Counter
c = Counter(['bob','steve','steve','joe'])
# c == Counter({'steve': 2, 'bob': 1, 'joe': 1})
c.update(['alan','jose','steve'])
# c == Counter({'steve': 3, 'jose': 1, 'bob': 1, 'joe': 1, 'alan': 1})
Upvotes: 3