OOPS - Re: [Tutor] this is ugly

Gregor Lingl glingl at aon.at
Tue Oct 21 02:48:13 EDT 2003


>   if line.find("KeC 923") != -1 or line.find("ZEF 156") != -1 or 
> line.find("pBX 88347") != -1 or line.find("FZX 17255") != -1:
>         #code if found
>
A quick suggestion:

   if -1 not in :
       # etc.

THIS SUGGESTIION WAS WRONG (error in boolean logic - what a shame!)

perhaps you like the the less nice 

   
   if [line.find(x) for x in 
         ["KeC 923","ZEF 156","pBX 88347","FZX 17255"]] != [-1]*4
 ?

    things = ["KeC 923","ZEF 156","pBX 88347","FZX 17255"]
    if sum([line.find(thing) for thing in things]) != -len(things)

sum is a built-in function since Python 2.3

Sorry for the inconvenience, I'm in a hurry
Gregor

>
> Thanks
> Gerhard
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>





More information about the Tutor mailing list