how to count occurrences of a list item in python code example
Example 1: python count matching elements in a list
# Basic syntax:
sum(1 for item in your_list if item == "some_condition")
# This counts the items in your_list for which item == "some_condition"
# is true. Of course, this can be changed to any conditional statement
Example 2: python find number of occurrences in list
student_grades = [9.1, 8.8, 10.0, 7.7, 6.8, 8.0, 10.0, 8.1, 10.0, 9.9]
samebnumber = student_grades.count(10.0)
print(samebnumber)
Example 3: python count occurrences of an item in a list
>>> [1, 2, 3, 4, 1, 4, 1].count(1)
3