I'm trying to read a text file. I need to read column values to list. My text file looks like this:
40 10 5 5
30 20 10 0
30 30 10 5
and desired output is
(40,30,30),(10,20,30),(5,10,10),(5,0,5)
I tried this code
def contest(filename):
contestFile = open(filename,'r')
contestFileLines=contestFile.readlines()
startColumn = 0
contestResult=[]
for x in contestFileLines:
contestResult.append(x.split()[startColumn])
contestFile.close()
print(contestResult)
contest("testing.txt")
and its output is just
['40', '30', '30']
What should I do?