[Tutor] Parsing Question
Emile van Sebille
emile at fenx.com
Sun May 10 02:25:13 CEST 2009
On 5/9/2009 4:23 PM Michael Morrissey said...
> Forgive me if I'm asking something stupid, but I'm not sure how to do
> this (there are so many options in Python, I'm overwhelmed and
> confused).
Look into the split method of string objects (which are what you should
be reading from the file), then look into indexing the resulting list
objects. That should focus your attentions...
Emile
> I have a text file that looks like this:
>
> 1 the 126 name
> 2 of 127 very
> 3 to 128 through
> 4 and 129 just
> 5 a 130 form
> 6 in 131 much
> 7 is 132 great
> etc...
>
> Each has 2 numbers and 2 words on it. Each number is related to the word
> that comes after it. So "1" and "the" are connected (kinda like a
> dictionary), and "126" and "name" are related.
>
> Using the above text file as an input, I'm trying to make an output that
> lists all the words, one word per line, but none of the numbers. I was
> hoping to get the words listed in order of their related numbers. So,
> the output needs to look like:
>
> the
> of
> to
> .... (skip to the 127th line)
> very
> through
> just
>
> I can open and loop over the text, I'm just not sure what commands I
> should use to parse each line. Can anyone give me suggestions or examples?
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list