I am using Python 2.7
I have two CSV files with similar lists, but with a few differences. I can compare the two files to get a list of strings of the records from the input list that do not match the correct list. But when iterating over the list of unmatched strings, I run into an issue...
I keep a simple count of the records that I process through in my for loop. When I get to the else statement, I remove spaces and when I remove the unmatched item from the list, I run into my issue. My noMatchList has 30 records. When that remove happens, I only get a count of 20 iterations instead of a full 30. With that remove commented out, I get a full 30 iterations.
Any idea what's going on here? Thanks for your time.
My relevant code:
for unMatched in noMatchList:
# Check if an uppercased version of the unMatched item is in GISlist. If so, remove the unMatched item
count +=1
upperCased = unMatched.upper()
if upperCased in GISlist:
noMatchList.remove(unMatched)
else:
# Check if the uppercased version of the unmatched item with no spaces around hyphen is in GISlist
# If it is in the GISlist, remove it.
if ' - ' in upperCased:
noSpaces = upperCased[0:upperCased.index('-')-1] + '-' + upperCased[upperCased.index('-')+2:]
if noSpaces in GISlist:
noMatchList.remove(unMatched)