I need to get a range of values from a large text file that contains epoch time stamps. I am currently looping through the file for start/end points, retrieving the line numbers, then iterating over the list again to retrieve the range values. This feels very inefficient because it involves looping over the list twice. Is there a better way?
start = '1509347040'
end = '1509347700'
with open('database.txt') as fp:
for i, line in enumerate(fp):
if start in line:
start=i
elif end in line:
end=i
break
for i, line in enumerate(fp):
if i >= start and i <= end:
print(i,line)