here,We are going to write python program to input a list of elements and search for given element in the list. We can easily check the existence of element in list using count() method. By using count method,We can check the number of times element exists in list.
python program to search given elements in list
numlist = []
listTot = int(input("Total List Items to enter = "))
for i in range(0, listTot):
value = input("Enter the %d List Item = " %i)
numlist.append(value)
searchele =input("Enter any element that you want to search :")
t = numlist.count(searchele)
if t>0:
print(" %s is found in list "%searchele)
else:
print("%s is not found in list:"%searchele)
Output
otal List Items to enter = 5 Enter the 0 List Item = 3 Enter the 1 List Item = 6 Enter the 2 List Item = 7 Enter the 3 List Item = 8 Enter the 4 List Item = 9 Enter any element that you want to search :9 9 is found Total List Items to enter = 5 Enter the 0 List Item = 88 Enter the 1 List Item = 33 Enter the 2 List Item = 56 Enter the 3 List Item = 77 Enter the 4 List Item = 78 Enter any element that you want to search :22 22 is not found in list:
Python Examples
<