Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python check if included in 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")
  
  
Source by utilities.tk #
 
PREVIOUS NEXT
Tagged: #python #check #included #list
ADD COMMENT
Topic
Name
5+9 =