0

I'm not sure how to explain it so here's an example:

array = ["x","x","x"]

if array == ["x","2","3"] or ["1","x","3"] or ["1","2","x"]:
    print ("hello")

Basically, how could I get this to only print hello if it is equal to one of those lists?

  • It looks like you might be able to simplify this particular case to `if array.count("x") == 1:`... :) – AKX Oct 18 '21 at 07:38

2 Answers2

0

Check if it is contained in a list of lists:

array = ["x","x","x"]

if array in [["x","2","3"],["1","x","3"],["1","2","x"]]:
    print ("hello")
David Meu
  • 1,527
  • 9
  • 14
0

You construct a temporary tuple (can be also list or set, but tuple is better) and check if it contains the value:

if array in (["x","2","3"], ["1","x","3"], ["1","2","x"]):
    print ("hello")
Expurple
  • 877
  • 6
  • 13