I am reading a file in python and i need to add every line to a list. The problem is that every line is a list containing string and integers. This is the file i am reading: file
this is the output of reading the file and putting it on the new list. output
as you can see it is storing me the lines as a string but it need to be like this: correct output
CODE:
JavaScript
x
11
11
1
def build_sets(f):
2
3
lista_valores = []
4
5
with open(f, 'r') as f:
6
for line in f:
7
lista_valores += line.strip().split('n')
8
9
print(lista_valores)
10
#pass
11
Advertisement
Answer
Try this in your for
loop:
JavaScript
1
2
1
lista_valores = line.strip('][').split(', ')
2
Also please only use english words to define your variables, it’s one of the main rules of variable naming conventions.