1

I have to extract a number(double) from a line. I am splitting the line into strings and extracting using the index. For example, if the string

line = 'The lowest temperature ever recorded on Earth was −128.6 F in the year 1983.'

I split this line and get the number:

line_str = line.split() 
temp = line_str[8]
year = line_str[13]

This will fail for the following line since -128.6 is now line_str[7].

line = 'Lowest temperature ever recorded on Earth was −128.6 F in the year 1983.'

Is there a versatile way of doing this?

Edit: I am making a list of both, the temperature and the year.

nac001
  • 693
  • 2
  • 9
  • 18

0 Answers0