List Count in Python
Level 246 keystrokes
This counts occurrences of a value in a list. The count() method returns how many times the value appears.
Python code
# Create a list that contains the value 2 three times1nums = [1, 2, 2, 3, 2, 4]# count(2) returns how many elements are equal to 2# The list is not changed; it prints 32print(nums.count(2))Output
3
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Python code and how often they appear.
,× 5(× 2)× 2.× 1[× 1]× 1=× 1