A
A
Artem2018-03-22 13:10:32
Python
Artem, 2018-03-22 13:10:32

How to correctly process a source string into a list in python?

There are strings of the form:
"2014 1.28 2.24 1.86 2.02 7.38 2015 1.87 1.59 2.47 1.51 7.44 2016 1.83 2.86 3.60 2.59 10.84 2017 2.34 2.89 3.06 3.16 11.45 2018 2.75 2.90 3.15 3.20 12.00"
"2014 1.61 1.69 1.72 1.35 6.37 2015 1.86 1.27 .75 .74 4.62 2016 .67 1.09 .85 .83 3.44 2017 1.28 1.49 1.95 1.53 6.25 2018 1.55 1.85 1.85 1.55 6.80"
The task is to split the string so that the resulting list contains data for one year (2014, 2015, etc.). With the first line, everything is simple - .split() the lines by spaces and take the values ​​by indexes. But there will be an error with the second line, because, for example, in the case of 2016, an extra space crept in (highlighted these places in bold) and instead of 1.09 we get 1 and .09, instead of 3.44 we get 3 and .44 . Is there any way to avoid this when processing strings? This insidious space can appear in random places other than the year value...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question