Maybe a title is confusing but here is my problem.
I go through django model objects with nested for loop as below. In the end I want to have dictionary which has unique key value pairs.
Below code works but I don't feel that it's really efficient.
settings = []
for feature in features:
for setting in feature.settings.all():
settings.append({"name": setting.name, "active": setting.active})
return [dict(t) for t in {tuple(setting.items()) for setting in settings}]
so before return I am having something like this:
[{'name': 'x', 'active': False}, {'name': 'y', 'active': True}, {'name': 'x', 'active': False}]
but when I return I remove duplicates in the list and return below.
[{'name': 'x', 'active': False}, {'name': 'y', 'active': True}]