HomePagev2 Forums Python Discussions count of data types from a list

Tagged: 

  • count of data types from a list

  • Sai Chaitanya Kumbhari Chaitanya Kumbhari

    Member
    December 21, 2020 at 4:04 pm

    hi fellas,

    for loop practice 2 i wrote a code like this

    def dtype(n):

    # yield helps to store multiple output in the function function alows 1 return statement

    #isinstance helps fine type of the element in the given list

    def count_data_type(n):

    yield sum(isinstance(i,int)for i in n)

    yield sum(isinstance(i,str)for i in n)

    yield sum(isinstance(i,float)for i in n)

    yield sum(isinstance(i,bool)for i in n)

    #yield is a generator object so we need to store the values in a container

    print(list(count_data_type([1,2.5,’micro’,0,3,4,6.5,’raptor’,6,0,True])))

    need suggestions and help

    thanks

Log in to reply.

Original Post
0 of 0 posts June 2018
Now