I want to delete items from a list, except those defined in an exception list. However, the code below skips every second entry, up to "one", after which it processes the rest of the attribute list as expected. Why is that?
ExceptionList = ['uno', 'dos', 'tres', 'cuatro', 'OID']
AttributeList = ['uno', 'dos', 'tres', 'cuatro', 'OID', 'one', 'two', 'three', 'four', 'five']
DeleteAttributes = AttributeList
print("Attributes: ", AttributeList)
print("Exception List: ", ExceptionList)
for Attribute in AttributeList:
print("Attribute: ", Attribute)
for Exception in ExceptionList:
if Exception == Attribute:
print("Exception: " + Attribute)
DeleteAttributes.remove(Attribute)
print("Delete Attributes: ", DeleteAttributes)
for Attribute in DeleteAttributes:
print("deleting.. ", Attribute)