string = "hello"
list = ["bye", "kasd", "hello", "day", "hel"]
if string in list:
print(f"Found '{string}' in '{list}'!")
else:
print(f"Couldnt find '{string}' in '{list}'!")
>>> Found 'hello' in '["bye", "kasd", "hello", "day", "hel"]'!
# app.py
listA = ['Stranger Things', 'S Education', 'Game of Thrones']
if 'Dark' in listA:
print("Yes, 'S Eductation' found in List : ", listA)
else:
print("Nope, 'Dark' not found in the list")
#This is the list. You can place it in other file and import it.
"In the same file:"
MyList = ["something", "something2", "something3"]
IncredibleWord = "something"
if IncredibleWord in MyList:
print("Yes, IncredibleWord is in your list")
else:
print("No, IncredibleWord isn't in your list")
#------------------------------------------------------------------------------
"If your list is in an other file:"
#OtherFile
MyList = ["something", "something2", "something3"]
#MyMainFile
#Variables and lists for example
from OtherFile import *
IncredibleWord = "something"
if IncredibleWord in MyList:
print("Yes, IncredibleWord is in your list")
else:
print("No, IncredibleWord isn't in your list")
#-------------------------------------------------------------------------------
#Only a variable or a list for example
from OtherFile import <List Name>
IncredibleWord = "something"
if IncredibleWord in MyList:
print("Yes, IncredibleWord is in your list")
else:
print("No, IncredibleWord isn't in your list")