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"]'!
#There's an all() and any() function to do this. To check if big contains ALL elements in small
result = all(elem in big for elem in small)
#To check if small contains ANY elements in big
result = any(elem in big for elem in small)
#the variable result would be boolean (TRUE/FALSE).
#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")