1👍
✅
You can do that using comprehensions only
result = [
{
'id': id,
'name': next(x['name'] for x in d if x['id'] == id),
'movies': [x['movie'] for x in d if x['id'] == id]
}
for id in set(x['id'] for x in d)]
but I highly doubt this would be more efficient or readable than a simple loop. KISS!
Source:stackexchange.com