I got a problem with reading csv. I can't use panda or other libraries so I coded this piece.
def read_csv(path):
with open(path, 'r') as f:
results = []
newresults= []
for line in f:
words = line.split(',')
print(words)
for i in words:
if i[-1:] == '\n':
i[-1:] = ""
results.append(words)
for lines in results:
if lines == []:
results.remove(lines)
for a in results:
newresults.append(tuple(a))
return newresults
I can't get to remove those \n at the end of every List within the main list.
[('Age', 'Gender', 'Weight (kg)', 'Height (cm)\n'), ('28', 'Female', '58', '168\n'), ('33', 'Male', '', '188\n')]
and my code above with
for i in words:
if i[-1:] == '\n':
i[-1:] = ""
doesn't work...
Thanks in advance