I am looping a CSV file, which is opened as dictionary. The problem is that while I loop through the rows in the dictionary, the main for loop goes to the next item. The dictionary does not reset to the first item when running the for loop. So if it gets to the last row, it doesn't change.
names = ['a', 'b', 'c', 'd', 'e', 'f']
source1_csv = open("output.csv", mode='r')
dictionary_csv = csv.DictReader(source1_csv)
for letters in names:
for entry in dictionary_csv:
print(entry["name"])
if entry['name'] == letters:
print("found it")
You can use any CSV file, just replace the key in the entry, and notice that if there is no match on the outer for loop, once that the next item in the names is selected, the inner for loop for the dictionary will just exit because the dictionary is already on the last position and does not reset.
How do I avoid this, so the position of the dictionary is reset and parse through every row for every entry of the names list?