New to Python, and have a very basic question:
I have a text file, which is formatted like the following example (the first number is a date, the second a value assosiated with it):
4.12. -11
5.12. 24
6.12. 192
7.12. -34
8.12. 921
I need a way to find the ‘value’ from the text file, for further use. The values can be pretty much anything – as long as they are numbers.
If you have only one vale separated by number of spaces (whitespace characters, to be precise):
Assumptions: the keys in first column are unique.
now you can access
data[value]to get the value, for example:If you can have multiple values per key/date, then:
Now the data will be a dictionary and values will be list of all values found in file. Therefore for file:
The
data['1.1']will be["10", "12"]You might have to add conversion of string to number to fully fit your requirements:
or: