I have tried using Counter() but everytime I do:
from collections import Counter
I get an error saying:
Traceback (most recent call last):
File "<web session>", line 1, in <module>
ImportError: cannot import name Counter
Do I actually have to make a file that has counter in it and then import it from there or something? I am a beginner so only the most basic answer will do.
Counter is only supported python2.7 and higher and is not available in earlier versions.
Use
from collections import Counter
and be sure that the C
letter of Counter
is a capital letter.
You can just cast the list to a set
instead:
l = ['a','b', 'c', 'a', 'd', 'e', 's', 'd', 'e', 'c']
print (len(set(l)) #prints 6
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