This is sort of a ridiculous and weird use case but bear with me, I have this list comprehension:
"reading_types": [
{
"name": rt.reading_type,
"value": rt.reading_type_id,
}
for unit in item.units
for rt in unit.reading_types
],
in a backend api call. It works great except that there will almost always be duplicates in the end result. How can I ensure that no duplicates are returned?
This is actually happening inside another list comprehension, and I can't reference the list at any point to remove duplicates so I must do so within the list comprehension itself.
I've tried using a set:
set([
{
"name": rt.reading_type,
"value": rt.reading_type_id,
}
for unit in item.units
for rt in unit.reading_types
])
but this results in the error: unhashable type: dict