Newbie: searching a list
Alex Martelli
aleaxit at yahoo.com
Wed May 23 18:02:51 EDT 2001
"user" <user at comm.mot.com> wrote in message
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:
sentence[sentence.index('=')+1]
should work, except you'll get an exception if the sentence
contains no item '=' (you may use try/except for that, of
course, if it is a possibility that you foresee).
Alex
More information about the Python-list
mailing list