Learn
Working with Lists in Python
Counting elements in a list
Suppose we have a list called letters
that represents the letters in the word “Mississippi”:
letters = ['m', 'i', 's', 's', 'i', 's', 's', 'i', 'p', 'p', 'i']
If we want to know how many times i
appears in this word, we can use the function count
:
num_i = letters.count('i') print(num_i)
This would print out:
4
Instructions
1.
Mrs. WIlson’s class is voting for class president. She has saved each student’s vote into the list votes
.
Use count
to determine how many students voted for 'Jake'
. Save your answer as jake_votes
.
2.
Use print
to examine jake_votes
.