TypeError, I know why but not how!?

John Machin sjmachin at lexicon.net
Thu Jul 10 13:28:35 CEST 2008

On Jul 10, 12:07 pm, ssecorp <circularf... at gmail.com> wrote:

>     pair1 = (student1,student2)
>     pair2 = (student2,student1)
>     if (pair1 or pair2) in incompatibles:

Apart from the problems that others have mentioned, the above
statement is NOT doing what you think it is. (pair1 or pair2) will
always produce pair1, because pair1, a tuple of length 2, cannot be
false. So the statement is equivalent to:
    if pair1 in incompatibles:
What you want is:
    if pair1 in incompatibles or pair2 in incompatibles:


More information about the Python-list mailing list