I have a list. Its pretty big. It has over 1 million entries. I want to count the frequency of each string in it. It stores numbers as strings from 1 to 1000. I have used the following but it keeps running for hours:
d = {b:a.count(b) for b in a}
n, m = d.keys(), d.values()
print n, m
Use collections.Counter
instead:
from collections import Counter
d = Counter(a)
n, m = d.keys(), d.values()
print n, m
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With