#Removes all the entries that have are non-US or have an invalid zip and
#all the entries that have the "DO NOT USE" or "DON'T USE" tag and
#all the entries that start with an '*' in address1 or address2.
for x in List[:]:
#make the addresses uppercase
add1 = x['address1'].upper()
add2 = x['address2'].upper()
if ((add1.find('DO') > -1 and add1.find('NOT') > -1) or add1.find("DON'T") > -1) and add1.find('USE') > -1:
i = List.index(x)
del(List[i])
elif ((add2.find('DO') > -1 and add2.find('NOT') > -1) or add2.find("DON'T") > -1) and add2.find('USE') > -1:
i = List.index(x)
del(List[i])
elif not x['zip'].isnumeric():
i = List.index(x)
del(List[i])
elif add1[:1] == '*' or add2[:1] == '*':
i = List.index(x)
del(List[i])
print(List[i]) #Output the line to check validity of entries removed
What is going wrong is the printed entries, what I believe should be only the entries that start with an '*', are not the correct entries. I have tried several things in my debugging process so far, I first used a counter for the variable i instead of finding the index of the corresponding entry, I added print to the other parts of the if..elif statement, but I have always gotten the wrong entries. Now I know it is deleting the right entries because there are no invalid entries left in the new file I output from the revised list. The only problem is I don't want it to delete extra entries. Maybe I am thinking about python data structures wrong, maybe I need to get out of the C++ mindset, or maybe the upper() isn't doing what I think it is doing. I hope I gave you guys all the info you need, any help learning here would be great. Thanks.

New Topic/Question
Reply




MultiQuote



|