I need to convert a list of dictionaries to a dictionary of dictionaries, with a particular item as the new key.
This is the way I'm currently doing it:
>>> a
[{'bar': 'baz', 'id': 'foo'}, {'bar': 'baz', 'id': 'qux'}]
>>> {
item['id']:{
sub_item:item[sub_item] for sub_item in item if sub_item != 'id'
} for item in a}
{'qux': {'bar': 'baz'}, 'foo': {'bar': 'baz'}}
However, this looks really ugly to me. Is there a more elegant way to do this?