Python Practice › List Programs › Program 67

Count integers in a mixed list

EasyList Programs · 67 of 100

Write a Python program to count the integers in a mixed list.

Advertisement
Input
["Hello", 45, "sqa", 23, 5, "Tools", 20]
Output
4

Approach

  1. Count items where isinstance(x, int).

Solution

Python
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.

More list programs

← All 100 List Programs

Leave a Comment