Newbie Question

Saint Malo samaloth at gmail.com
Mon Jun 19 22:37:09 EDT 2006


BTW my program isn't about red blue yellow etc.  I'm just using it as
an example.  I guess i didn't asked the question correctly or am not
expressing myself correctly.   Let me try one more.

Ok.

Contents of text file follow:

red blue purble
yellow blue green



Now lets imagine i wrote some code to look for the word red.  Once the
program has found red i want it to print something like the following
line.


If you add red and blue you obtain the color purple...


How do i turn each color in the line into a separate string? Now is
that possible?





placid wrote:
> 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