0

If I have a text such as:

There was no possibility of taking a walk that day
We had been wandering indeed in the leafless shrubbery an hour in the morning but since dinner (Mrs Reed when there was no company dined early) the cold winter wind had brought with it clouds so sombre and a rain so penetrating that further out door exercise was now out of the question
I was glad of it I never liked long walks especially on chilly afternoons dreadful to me was the coming home in the raw twilight with nipped fingers and toes and a heart saddened by the chidings of Bessie the nurse and humbled by the consciousness of my physical inferiority to Eliza John and Georgiana Reed
The said Eliza John and Georgiana were now clustered round their mama in the drawing room she lay reclined on a sofa by the fireside and with her darlings about her (for the time neither quarrelling nor crying) looked perfectly happy

and I wanted to create a list such as: (I want to attach like a listing in front of the sentences, but depending on the position of the sentence)

0: There was no possibility of taking a walk that day
1: We had been wandering indeed in the leafless shrubbery an hour in the morning but since dinner (Mrs Reed when there was no company dined early) the cold winter wind had brought with it clouds so sombre and a rain so penetrating that further out door exercise was now out of the question
2: I was glad of it I never liked long walks especially on chilly afternoons dreadful to me was the coming home in the raw twilight with nipped fingers and toes and a heart saddened by the chidings of Bessie the nurse and humbled by the consciousness of my physical inferiority to Eliza John and Georgiana Reed
3: The said Eliza John and Georgiana were now clustered round their mama in the drawing room she lay reclined on a sofa by the fireside and with her darlings about her (for the time neither quarrelling nor crying) looked perfectly happy

How would i go about it?

Obviously, the first sentence would be 0, because the first sentence in this paragraph will be regarded as a 0, when we consider counting in indice rule. What i tried was

for line in open("MYEXAMPLETEXT"):
  line_strip = line.rstrip()
  words = line_strip.split()

  print(line_strip[0],":", words)

Except obviously line_strip[0] is wrong because it prints out the first letter in each word so it will look like:

T: There was no possibility of taking a walk that day
W: We had been wandering indeed in the leafless shrubbery an hour in the morning but since dinner (Mrs Reed when there was no company dined early) the cold winter wind had brought with it clouds so sombre and a rain so penetrating that further out door exercise was now out of the question
I: I was glad of it I never liked long walks especially on chilly afternoons dreadful to me was the coming home in the raw twilight with nipped fingers and toes and a heart saddened by the chidings of Bessie the nurse and humbled by the consciousness of my physical inferiority to Eliza John and Georgiana Reed
T: The said Eliza John and Georgiana were now clustered round their mama in the drawing room she lay reclined on a sofa by the fireside and with her darlings about her (for the time neither quarrelling nor crying) looked perfectly happy

I just need to consider the position of the sentence in terms of the overall paragraph of text???

D.Ronald
  • 172
  • 6

1 Answers1

0

Nevermind. I realised I could initialise a value at first, e.g.

  count = -1
  for line in open("MYEXAMPLETEXT"):
   line_strip = line.rstrip()
   words = line_strip.split()
  count += 1

  print(count,":", words)
D.Ronald
  • 172
  • 6
  • You could do it in one line: `print(''.join('%d:%s'%(i,line) for i,line in enumerate(open("MYEXAMPLETEXT"))))` – mshsayem Apr 22 '18 at 14:52