I have a huge text file with integers. I need to process them line by line and save it in separate lists based on some calculations on numbers in each line
The end goal is to load the numbers(except line 1) in to two list - A = numbers at odd positions B = numbers at even positions
File sample:
1 3 4 5
3 4 56 73
3 4 5 6
Currently I am doing as:
with open(filename) as f:
for line in f:
line = line.split()
line_num = line_num + 1
if line_num == 1:
# do something
pass
if line_num > 1:
line = [int(i) for i in line]
for x in range(len(line)):
# do something
pass
The problem is, it is taking a lot of time. Is there a better way to do this fast?