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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -