[Tutor] the and command
Ricardo Aráoz
ricaraoz at gmail.com
Fri Aug 24 16:19:35 CEST 2007
Alan Gauld wrote:
> "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:
>
or also : if num in l1 + l2 + l3 + l4 + l5 :
> 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,
>
More information about the Tutor
mailing list