Hello everyone welcome to another video, In this video I will show you how to search element in list to python programming. First I'll explain logic and later implementation, genuine approach of every programming language, In python programming using keyword to element existence in list.
Python code
l = [2, 3, 7, 5, 8]
k = 5
def solve(list1, key):
for i in range(len(list1)):
if list1[i] == key:
return True
return False
if solve(l, k):
print("Element found")
else:
print("Element not found")
Output - Element found
----------------------------------------------------------
l = [3, 4, 5, 6]
k = 6
if element found
return its index
otherwise return -1
def solve(l, k):
for i in range(len(l)):
if l[i] == k:
return i+1
return -1
print(solve(l, k))
Output - 4
----------------------------------------------
python project — Number guessing game using : • Random module in python | number guessing ...
Python
OOPs Tutorial — • Object Oriented Programming in python | oo... Python
Programming Playlist in Hindi :- • Python Toturial for Beginners in Hindi
Join Telegram channel — t.me/bundelkhand_education
HTML tutorial in Hindi — • HTML tutorial in hindi