I have a loop that iterates over 2 lists.
excel_data
is a list that is created from an excel spreadsheet, the new data.
exists
is a list that is created from a sql query, the existing data.
I need to compare the two and do a SQL UPDATE if the 2nd column of the 2d list excel_data
has a changed value for the same record from exists
.
Currently, the loop that is taking up the time is
excel_data = [[0 for x in range(2)] for y in range(20000)]
exists = [[0 for x in range(2)] for y in range(20000)]
for i in range(0, len(excel_data)):
for j in range(0, len(exists)):
if exists[j][0] in excel_data[i][0] and exists[j][1] != excel_data[i][1]:
print("")
Since both lists are slightly less than 20,000 in size and will only increase as time goes on, this is the equivalent of iterating 400 million times. It completes after a few minutes, but I was wondering if there is any way I can substantially reduce the number of iterations or some other shorter way to get the index of a row which has a difference in the 2nd column.
Input data is like this:
Sam Adams **********@gmail.com
Sammy Adams **********@gmail.com
Samuel Adams **********@gmail.com
Samantha Adams **********@gmail.com
Sam Adams **********@gmail.com
I am searching to see if the 2nd column, in this case an email has any sort of change for the given name in the same row.