Python Practice › List Programs › Program 67
Count integers in a mixed list
Write a Python program to count the integers in a mixed list.
Input
["Hello", 45, "sqa", 23, 5, "Tools", 20]
Output
4
Approach
- Count items where
isinstance(x, int).
Solution
data = ["Hello", 45, "sqa", 23, 5, "Tools", 20]print(sum(isinstance(x, int) for x in data))Output
4
Line by line
Line 2
Each True counts as 1 when summed.
Learn the concept
New to this topic? Read the lesson, then come back.