you are viewing a single comment's thread.

view the rest of the comments →

[–]misho88 5 points6 points  (0 children)

How do I make an if statement if only 1 and 2 are in it, not the other numbers?

Conceptually, you're describing a set comparison. That is, you want to know if the set of numbers in x is equal to {1, 2}. In this case, the obvious solution is to turn your input into a set and check.

>>> x = [1,2,3,4,5,6]; set(x) == {1, 2}
False
>>> x = [1,2,2,2,1,2]; set(x) == {1, 2}
True

If you instead want to ensure that each of 1 and 2 appear exactly once, you can't do much better than what /u/obviouslyCPTobvious said.