counter in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

counter in python

I was taking the python course and in (control structures- loop) it mentions counter in a code but it never went over what counter means and how to use it can someone break it down for a beginner how i can use it. print Counter(['B','B','A','B','C']) It said error

18th May 2020, 6:07 PM
Jah Revelo
Jah Revelo - avatar
6 Answers
+ 4
I don't think there is a course specifically about the Counter class, but you can find details on the web: https://stackabuse.com/introduction-to-pythons-collections-module/
18th May 2020, 11:00 PM
Sebastian Pacurar
Sebastian Pacurar - avatar
+ 2
It counts the no of occurrences of each letter and implement them as key value pair in dictionary You need to import it from collections to use it
18th May 2020, 6:15 PM
Abhay
Abhay - avatar
+ 2
from collections import Counter print(Counter(['a','b','b','b','a','c']))
18th May 2020, 6:31 PM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Ty does anyone know in the python course where does it go over counter. I looked through the sections in control structure and I must have missed it. For instance that whole line "from collections import counter" I never even seen that in the python tutorial.
18th May 2020, 9:08 PM
Jah Revelo
Jah Revelo - avatar
+ 1
Thank you
18th May 2020, 11:42 PM
Jah Revelo
Jah Revelo - avatar
0
Can you give me a basic example of what you said so I can study it for example what did I do wrong in the code above
18th May 2020, 6:19 PM
Jah Revelo
Jah Revelo - avatar