I am trying to compare specific values between two csv files. I read in both csv files using the csv.DictReader() function and I have a nested for loop with each going through one of the readers. Of course, normally the inner for loop will reset and go through the entirety of its loop for each iteration of the outer loop, but this is not the case for me. When using my debugger, I can see on the second iteration of the outer loop, the code skips past the inner loop entirely as if there isn't anything to loop over. Is this due to a property of looping through the dictionary reader object? If so, how can I fix it? I have included a snippet of my code below.
with open('csv1.csv', 'r') as inFile1:
with open('csv2.csv', 'r') as inFile2:
reader1 = csv.DictReader(inFile1)
reader2 = csv.DictReader(inFile2)
for row1 in reader1:
for row2 in reader2:
if row1['key1'] == row2['key2']:
[Perform other operations here]