I'm creating a dynamic array of UUIDs, and I have another list of existing UUIDs, I want to delete items from the existing list that aren't in the new dynamic list. I'm trying to do this like this
# Remove components that aren't being updated
new_component_id_for_existing_sections = []
for component in new_components:
if component.get('section_holder_id'):
new_component_id_for_existing_sections.append(component.get('component_id'))
print('New component IDs')
for com in new_component_id_for_existing_sections:
print(com)
print('Checking existing components')
for existing_component in self.get_object().components.all():
print(existing_component.component.id)
print(existing_component.component.id not in new_component_id_for_existing_sections)
So in here I create the array new_component_id_for_existing_sections which in my example has two IDs in, and self.get_object().components.all() has 3 ids in. But the output for this gives me.
New component IDs
acae9374-d32d-4752-ba5a-9437a54dbbe7
a2a9d893-86ba-4d1d-938e-f638e7b2a4b2
Checking existing components
f3cb3cc6-4d66-4df5-8232-2c1f858c8632 <----Not in the array but returns that it is
True
acae9374-d32d-4752-ba5a-9437a54dbbe7
True
a2a9d893-86ba-4d1d-938e-f638e7b2a4b2
True
The first item is saying it's in the array, but it isn't and I can't figure out why
setand take difference?new_component_id_for_existing_sections. From the looks of it, the first one should printTrue, and the other twoFalse– not the other way around.