- #1
Jonas
- 6
- 1
- TL;DR Summary
- Trying to retrieve integers from two separeate files with different conditions.
Hey.
Im pretty new to Python (and programming in general in fact). I have received two different files, each containing 10 000 integers mixed up with some commas, colons, and \n, and in one of the files there are also negative numbers. I have tried all day retrieving those numbers using all the different techniques i have found online, in the books etc to be able to finish the excercise. But nothing seems to work, i can't convert them to floats or integers no matter what i do. The files are formatted in such way that it's 10 numbers ( in one of them it's ranging from -999 to 999, and in the other from 0 to 999) per row and then a line-break.
This gives the result 1000 (length of list).
If i try to convert a to int or float i get an error. So i interpret that as one line from the file => one entry in the list. Whereas i would like to think that there are 10 000 entries - one for each value. The task after this is trivial, calculate mean and standard dev. If anyone have an idea i would be thankful.
Im pretty new to Python (and programming in general in fact). I have received two different files, each containing 10 000 integers mixed up with some commas, colons, and \n, and in one of the files there are also negative numbers. I have tried all day retrieving those numbers using all the different techniques i have found online, in the books etc to be able to finish the excercise. But nothing seems to work, i can't convert them to floats or integers no matter what i do. The files are formatted in such way that it's 10 numbers ( in one of them it's ranging from -999 to 999, and in the other from 0 to 999) per row and then a line-break.
Code:
with open(numbers_A) as f:
for line in f:
line = line.strip()
a = line.replace(',','')
lista.append(a)
print(len(lista))
This gives the result 1000 (length of list).
If i try to convert a to int or float i get an error. So i interpret that as one line from the file => one entry in the list. Whereas i would like to think that there are 10 000 entries - one for each value. The task after this is trivial, calculate mean and standard dev. If anyone have an idea i would be thankful.