reduce python list of objects to dict object.id -> object
- by Dmitry Teslenko
Hello!
You have list of objects each of them have id property.
Here's my way to covert it to dict where keys are ids and values are objects:
reduce(
lambda x,y: dict(x.items() + { y.id : y}.items()),
list,
{}
)
Suggest better way to do it.