Write a python program to counting item occurrences

Write a python program to counting item occurrences

Program
from collections import Counter
def myfun():
    
    list1 = ['sateesh','kumar', 'sateesh', 'Varshini', 'Kumar']
    count = Counter(list1).get("sateesh")
    print("The name Sateesh appears in the list ",count," times.")
    
if __name__=="__main__":
    myfun()


Output:

The name Sateesh appears in the list 2 times.


Program

from collections import Counter
def myfun():
    
    list1 = ['sateesh','kumar', 'sateesh', 'Varshini', 'Kumar']
    count = 0
    for name in list1:
        if name == 'sateesh':
            count +=1
    print("The name Sateesh appears in the list ",count," times.")
    
if __name__=="__main__":
    myfun()



Output:

The name Sateesh appears in the list 2 times.



More Questions


33 . Write a python program to counting item occurrences
34 . Write a python program to print flatten a nested list
35 . Write a python program to Find the index of the largest number in the list
36 . Write a python program to Find the index of the smallest number in the list
37 . Write a python program to find absolute value of a number in the list
38 . Write a python program to adding a thousand separator
39 . Write a python program startswith and Endswith Methods
40 . Write a python program to print Nlargest numbers
41 . Write a python program to print Nsmallest numbers



For latest job updates join Telegram Channel: https://t.me/sateeshm