Given an array of dicts of name–value pairs, what is the most effective or most Pythonic method for converting them to a dictionary with the names as keys and and values as the values?
Here's what I've come up. It's pretty short and seems to work fine, but is there some built-in function for doing just this sort of thing?
verbose_attributes = [
{
'Name': 'id',
'Value': 'd3f23fa5'
},
{
'Name': 'first_name',
'Value': 'Guido'
},
{
'Name': 'last_name',
'Value': 'van Rossum'
}]
attributes = {}
for pair in verbose_attributes:
attributes[pair['Name']] = pair['Value']
print(repr(attributes))
# {'id': 'd3f23fa5', 'first_name': 'Guido', 'last_name': 'van Rossum'}
In short, is there a better way of converting verbose_attributes
to attributes
?