Im currently uniquifying a list of objects based on their name attribute by creating a dict of objects with the name value as the dict key like this:
obj_dict = dict()
for obj in obj_list:
if not obj.name in obj_dict:
obj_dict[obj.name] = obj
new_obj_list = obj_dict.items()
And I was wondering if there was a quicker or more pythonic way to do this.
If two objects with the same name should always considered identical you could implement
__eq__and__hash__accordingly. Then your solution would be as easy as storing all your objects in aset():Converting the list back to a set is probably not even necessary since the order is lost anyway so unless you need to do something with it that only works with a list but not with a set just keep using the set.