I was trying to make a basic search function in python using conditions and for loops like this:
emails = ["me@gmail.com", "you@hotmail.com", "them@yahoo.com"]
def search(keyword):
for i in emails:
if keyword in i:
return i
else:
return "Item not found"
keyword = input("Enter search term: ")
print (search(keyword))
but my function only works when the keyword is part of the first item. for example if I tried searching for 'me' or 'gmail' it would return "me@gmail.com"
mac$ python3 for_loop.py
Enter search term: gmail
me@gmail.com
If I tried searching for 'you', it returns the false (else) statement "Item not found".
mac$ python3 for_loop.py
Enter search term: hot
Item not found
What am I doing wrong?