-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
  • 45,791
  • 17
  • 81
  • 97
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
  • 27,712
  • 9
  • 72
  • 90
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,910
  • 2
  • 13
  • 21