-1

I have the following list:

A = [x,y,z]

and I need help with writing a code in Python that returns True if any combination of x or y or z is in the list, but returns False if any other variables outside of A is in the list.

Example:

B = [x]  (return True)
B = [l] (return False)
B = [x,z] (return True)
B = [x,y,z,l] (return False)
Martin Evans
  • 43,220
  • 16
  • 78
  • 90
kchiang
  • 29
  • 1

2 Answers2

1

You can make a set from your list, and check if the elements are its subset

sA = set(list)
sE = set(elements)
check = sE <= sA
blue_note
  • 25,410
  • 6
  • 56
  • 79
0
def b(list_of_b):
    A = ['X', 'Y', 'Z']
    for i in list_of_b:
        if i in A:
            return True
    return False
print(b(['X','Y']))

This may help Happy Coding

Dev Jalla
  • 1,424
  • 2
  • 11
  • 19