Newbie Question

placid Bulkan at gmail.com
Mon Jun 19 21:43:21 EDT 2006


BartlebyScrivener wrote:
> Saint Malo wrote:
> > If the program searches for blue, i just want it to print blue
>
> Huh? Tell it to print whatever you want.
>
> for line in file:
>     if 'blue' in line:
>         print 'blue'
>
> for line in file:
>     if 'brown' in line:
>         print 'brown'
>
> for line in file:
>     if 'red' in line:
>         print 'weasels rip my flesh'

wow Dude, this is not efficient at all! You only need to read the file
once not as many times as there are words in your looking for in the
lines of the file




More information about the Python-list mailing list