Another way:
>>> a = [1, 1.23, 'abc', 'ABC', 6.45, 2, 3, 4, 4.98] >>> len(filter(lambda e: isinstance(e, int), a)) 4
You should be aware that any approach that uses isinstance will consider True or False as int since bool is a subclass of int:
>>> isinstance(False, int) True >>> type(False)==int False
So, if the difference between int and bool matters, use type(whatever)==int .
source share