Python Program to Count Occurrences of Items in a Python List Using count()
# Count the Occurrence of an Item in a List Using count() in python # Python code to count the number of occurrences def countX(lst, x): return lst.count(x) # Driver Code lst = [1,4,5,7,4,9,1,6,1,3,6,8,1,9,8,4,1,1] x = 1 print('{} has occurred {} times'.format(x,countX(lst, x)))
Output:
1 has occurred 6 times