count how many of an object type there are in a list Python -
if have list in python:
a = [1, 1.23, 'abc', 'abc', 6.45, 2, 3, 4, 4.98]
is there easy way count amount of object type there in a
? simpler following produces same result:
l = [i in if type(a[i]) == int] print(len(l))
hopefully made myself clear.
a = [1, 1.23, 'abc', 'abc', 6.45, 2, 3, 4, 4.98] sum(isinstance(i, int) in a)
which returns
4
Comments
Post a Comment