[Answer]-Combine a list of dictionaries ; specific use case

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!

👤georg

Leave a comment