Table of Contents
- Count total items in the list
- Count occurence of each element in the list
In this tutorial, we will see how to count items inlist in python
Count total items in the list
You can use len[] function to count items in the list.
Lets understand with the help of example.
1 2 3 4 5 6 | list1=[1,2,3,4] print["List:",list1] length=len[list1] print["Length of list1",length] |
Output:
List: [1, 2, 3, 4] Length of list1: 4
Count occurence of each element in the list
1 2 3 4 5 | list1=[1,2,3,4,1,4,3,2,2,1,5] print["List:",list1] print["Count of 2 in list1:",list1.count[2]] |
Output:
List: [1, 2, 3, 4, 1, 4, 3, 2, 2, 1, 5] Count of 2 in list1 3
Thats all about Python count items in the list.
import_contacts
You may also like:
Callback function in Python
[Fixed] ValueError: too many values to unpack [expected 2]
List of Dictionaries in Python
Python If with NOT Operator
Python If with And Operator
NoneType in Python
How to check for null in Python
Split String With Multiple Delimiters In Python
Sort dictionary by value in python
Get class name in Python
- 1
- 2
- 3
- 22