[Tutor] the and command

Kent Johnson kent37 at tds.net
Sat Aug 25 01:13:29 CEST 2007


Ricardo Aráoz wrote:
> 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 :

No, that has a different meaning, it is true if num is in *any* of the 
lists; the original version requires num to be in *all* of the lists.

Also your version will compute the sum of lists every time through the 
loop which you don't really want...

Kent


More information about the Tutor mailing list