Q:

Check if element in list Python

thislist = ["apple", "banana", "cherry"]
if "apple" in thislist:
  print("Yes, 'apple' is in the fruits list")
8
# To check if a certain element is contained in a list use 'in'
bikes = ['trek', 'redline', 'giant']
'trek' in bikes
# Output:
# True
11
if value in list:
  #do stuff

#Also to check if it doesn't contain
if value not in list:
  #do stuff
3
# 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")
1
arr_test = ["thetung1","thetung2","thetung3"]
title = "thetung"
if title not in arr_test:
	arr_test.append(title)
0
listA = [item1, item2, item3]
if item4 in listA:
  print('yes, item4 is in the list')
else:
  print('no, item4 is not in the list')
0
'''    
    check if list1 contains all elements in list2
'''
result =  all(elem in list1  for elem in list2)
if result:
    print("Yes, list1 contains all elements in list2")    
else :
    print("No, list1 does not contains all elements in list2"
-1

New to Communities?

Join the community