Advertisements
Advertisements
प्रश्न
Write a program to find the number of times an element occurs in the list.
संक्षेप में उत्तर
उत्तर
Program:
#defining a list
list1 = [10, 20, 30, 40, 50, 60, 20, 50, 10, 30, 50, 30, 24, 45]
#printing the list for the user
print("The list is:",list1)
#asking the element to count
inp = int(input("Which element occurrence would you like to count? "))
#using the count function
count = list1.count(inp)
#printing the output
print("The count of element",inp,"in the list is:",count)
OUTPUT:
The list is: [10, 20, 30, 40, 50, 60, 20, 50, 10, 30, 50, 30, 24, 45]
which element occurrence would you like to count? 10
The count of element 10 in the list is: 2
shaalaa.com
List
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
APPEARS IN
संबंधित प्रश्न
What will be the output of the following statement?
list1 = [12,32,65,26,80,10]
list1.sort()
print(list1)
What will be the output of the following statement?
list1 = [12,32,65,26,80,10]
sorted(list1)
print(list1)
What will be the output of the following statement?
list1 = [1,2,3,4,5,6,7,8,9,10]
list1[::-2]
list1[:3] + list1[3:]
What will be the output of the following statement?
list1 = [1,2,3,4,5]
list1[len(list1)-1]