xxxxxxxxxx
l1 = [1]
l2 = [2,3,4]
if len(set(l1).intersection(set(l2)))==0:
print('1 is not in the list (l2)')
else: # len()>0
print('1 is in the list (l2)')
xxxxxxxxxx
thelist = ["apple", "avocado", "banana"]
inpt = input("Check an item in the list: ")
if inpt in thelist:
print(inpt, "is in the list!")
xxxxxxxxxx
listA = [item1, item2, item3]
if item4 in listA:
print('yes, item4 is in the list')
else:
print('no, item4 is not in the list')
xxxxxxxxxx
if value in list:
#do stuff
#Also to check if it doesn't contain
if value not in list:
#do stuff
xxxxxxxxxx
#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")
xxxxxxxxxx
# plz suscribe to my youtube channel -->
# https://www.youtube.com/channel/UC-sfqidn2fKZslHWnm5qe-A
fruits = ["apple", "banana", "cherry","banana"]
item = "apple"
if item in fruits:
print("Yes, '",item,"' is in the fruits list")
xxxxxxxxxx
my_list = [1, 2, 3, 4]
# Check if 3 is in the list
if 3 in my_list:
print("3 is in the list")
# Check if 5 is not in the list
if 5 not in my_list:
print("5 is not in the list")