[Tutor] the and command
Alan Gauld
alan.gauld at btinternet.com
Fri Aug 24 09:25:33 CEST 2007
"max baseman" <dos.fool at gmail.com> wrote
> im checking if a number is in all 5 of the other lists and when
> i use the and command it seems to just be checking if it's in a
> least
> one of the others,
> for num in l2 and l3 and l4 and l5 and l6: # here seems to be the
Try:
if num in I2 and num in I3 and num in I4 and num in I5 and num in I6:
In your case you are 'and'ing the lists which is a boolean expression
and because of how Python does short circuit evaluation it returns
the last list
>>> a = [1,2]
>>> b = [3,4]
>>> a and b
[3, 4]
so
for n in a and b:
is the same as
for n in b:
which iterates over b...
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list