Updating list to iterate while iterating

Hi guys, I've got this list of non-persistable objects which contains duplicates. The id of the object is different, but the attribute value is the same. Goal: I want to create a list without any duplicates in attribute value. So, what I'm doing right now is iterate over the list. For every object, I filter the original list on attribute value. If a duplicate is found, I remove it from the list to iterate over and delete it. Problem: I see the number of objects in the original list decreasing, but the loop still iterates over the objects I removed and deleted. It seems the loop has a list in cache that doesn't respond to list-actions within the loop. Is there another way to do this? Thanks!
2 answers

A simple solution could be to create a new list of the same entity. Then iterate over the original list (with duplicates), and do a Find operation on the newly created list on basis of the attribute value. If it is found, continue (since the value is already in the list and thus not unique). If not found, you add it to the newly created list. This way, you will end up with a new list only containing unique values. 


Why do you not use the list operation union? https://docs.mendix.com/refguide6/list-operation

Or are they different objects?




And what you think you should do otherwise is create a new list and do the iteration. In the iteration add it to the new list. At the end you could even union the list over itself to make sure you have a list without duplicates.