Find any value in list


(blenderaptor) #1

Hi !

a = [1,2,3]
a == [1,2,3]
True
a == [1,?,3]

What should i write instead of “?” to obtain True whatever its value?


(mavek) #2

python doesn’t really work that way. What you did is set a to a list and then test that a matches the same list.

The fastest way to solve this question is to break it up.

a[0] == 1 and a[2] == 3

but I suspect this is not the answer you were really looking for.

you could also use in

1 in a and 3 in a

but that isn’t postionally aware, if 1 and 3 swapped positions the first statment would be False but the second on would be True


(blenderaptor) #3

indeed. its not the answer i’m looking for. Im surprised that python doesnt has an elegant solution for this.


(j) #4

Conversion and a kind of like an 3d boolean ->

>>> a = [1,2,3]
>>> b = [1,3]
>>> a = set(a)
>>> b = set(b)
>>> x = a.difference(b)
>>> x
{2}
>>> 

or

>>> {1,2,3}.difference({1,3})
{2}
>>>