I'm rather new to Python, and am running into the following error when using a nested for loop
IndexError: list index out of range
Here is my code
count = 0
count2 = 1
rlength = range(len(records))
for i in rlength:
ex = records[count].id
for bla in rlength:
if re.search(ex, records[count2].id) != None:
print records[count2].id
count2 += 1
count += 1
count2 = count + 1
Edit:
Fixed with the following code
rlength = range(len(records))
for i in rlength:
ex = records[i].id
for bla in rlength:
if bla + 1 < len(rlength) and re.search(ex, records[bla + 1].id) != None:
print records[bla].id
countandcount2at all. You can just useiandblainstead and your for loops will always remain within the range.