Yoshi
0
Q:

python check if list contains

## checking all elements of list_B in list_A
list_A = [1, 2, 3, 4]
list_B = [2, 3]

check = all(item in list_A for item in list_B)

print(check)
# True
2
# To check if a certain element is contained in a list use 'in'
bikes = ['trek', 'redline', 'giant']
'trek' in bikes
# Output:
# True
11
some_list = ['abc-123', 'def-456', 'ghi-789', 'abc-456']
if any("abc" in s for s in some_list):
    # whatever
0
if value in list:
  #do stuff

#Also to check if it doesn't contain
if value not in list:
  #do stuff
3

New to Communities?

Join the community