Newbie: searching a list

Thomas Wagner gluon at web.de
Wed May 23 13:05:51 EDT 2001


sorry, the following snippet works fine:

      sentence = ['Independent', 'Variable', '=', '11', ';']
      item = sentence[sentence.index('=') + 1]

Thomas


"Thomas Wagner" <gluon at web.de> schrieb im Newsbeitrag
news:9egqhr$19uq$1 at news.space.net...
> try this instead
>
>     sentence = ['Independent', 'Variable', '=', '11', ';']
>     sentence[sentence.index('=') + 1]
>
> (it is an error, if there is no '='-item)
>
> Thomas
>
> "user" <user at comm.mot.com> schrieb im Newsbeitrag
> news:3B0BE2ED.F480A336 at comm.mot.com...
> > I have a list generated from a "sentence=split(some_file.readline())"
> > statement.
> >
> > A sample list resulting from this statement is:
> >     ['Independent', 'Variable', '=', '11', ';']
> >
> > I want to extract the '11', which is the next item in the list following
> > the equals sign; I thought to get it this way:
> >
> > found=0
> > IV=''
> > for item in sentence:
> >     if found:
> >         IV=item
> >         break
> >     if item == "=":
> >         found=1
> >
> > This works, but is it the best way to do it?
> >
> > -- Stephen
> >
>
>





More information about the Python-list mailing list