In this example, you will learn to count the occurrence of an item in a list.
To understand this example, you should have the knowledge of the following Python programming topics:
Using count() method
freq = ['a', 1, 'a', 4, 3, 2, 'a'].count('a') print(freq)
Output
3
Using count()
method, pass the item to be counted. As shown above, 'a'
is passed, which gives the total number of occurrences of character 'a'
.
You can learn more about count()
at Python count().
Related posts:
Python String istitle()
Python Program to Iterate Through Two Lists in Parallel
Python Type Conversion and Type Casting
Python Numbers, Type Conversion and Mathematics
Python Program to Measure the Elapsed Time in Python
Python len()
Python Program to Create a Long Multiline String
Python Functions
Python bytearray()
Python Tuple
Python String isalnum()
Python Deep Learning Cookbook - Indra den Bakker
Python Program to Extract Extension From the File Name
Python Program to Display Fibonacci Sequence Using Recursion
Python Statement, Indentation and Comments
Python Program to Print Colored Text to the Terminal
Python Program to Sort a Dictionary by Value
Python timestamp to datetime and vice-versa
Python String isdecimal()
Deep Learning with Python - Francois Cholletf
Python Program to Randomly Select an Element From the List
Python Iterators
Python Program to Create Pyramid Patterns
Deep Learning in Python - LazyProgrammer
Python Program to Find HCF or GCD
Python Dictionary fromkeys()
Python Namespace and Scope
Python float()
Python Program to Find ASCII Value of Character
Python Data Structures and Algorithms - Benjamin Baka
Python set()
Python Program to Calculate the Area of a Triangle