[Tutor] Compound if statement question.

Greg Christian glchristian at comcast.net
Sun May 1 20:28:43 CEST 2011


Is there a way to write an if statement that will pick up duplicates (two ‘1’s):

L = ['1', '4', '1']
if (L[0]) != (L[1]) != (L[2]):
    print "THEY ARE NOT EQUAL"
else:
    print "THEY ARE EQUAL"

When I run this code, it prints “THEY ARE NOT EQUAL” when it should print the else “THEY ARE EQUAL”.

list L has two ‘1’s; therefore I am trying to get an if statement that will recognize this. When using the != (not equal) operator, shouldn’t the if be true when items in list are not the same? Any input would be appreciated.

Thanks,

Greg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110501/58025abb/attachment.html>


More information about the Tutor mailing list