I would like to append an empty list within a for loop. Currently this is what I have:
iteration = 0
with open(logFile, 'r') as logfile_read:
for line in logfile_read:
line = line.rstrip()
if 'Time' in line:
iteration_time = re.findall(r'^Time\s+=\s+(.*)', line)
for t in iteration_time:
iteration = iteration +1
print iteration, iteration_time
Here, iteration_time is a list varying from 0.1 to 0.5 in increments of 0.1. The output that I get with this is:
1 ['0.1']
2 ['0.2']
3 ['0.3']
4 ['0.4']
5 ['0.5']
However, I would like to assign an empty list to iteration such as iteration = [] and then be able to extend by 1 increment for every value of t within the for loop rather than using iteration = iteration +1.
enumerate()will start at 0, unless you use its optional second argument to change that)r'^Time\s+=\s+(.*)'will match because my log file will always haveTimein it @smci