I've done some searching, playing and still can't seem to find a solution.
Say I have a list of dictionaries such as:
listofdicts = [
{'Name': 'Jim', 'Attribute': 'Height', 'Value': '6.3'},
{'Name': 'Jim', 'Attribute': 'Weight', 'Value': '170'},
{'Name': 'Mary', 'Attribute': 'Height', 'Value': '5.5'},
{'Name': 'Mary', 'Attribute': 'Weight', 'Value': '140'}
]
But I want to place each of those in a singular named dictionary, such as:
listofdicts = [
{'Person': {'Name': 'Jim', 'Attribute': 'Height', 'Value': '6.3'}},
{'Person': {'Name': 'Jim', 'Attribute': 'Weight', 'Value': '170'}},
{'Person': {'Name': 'Mary', 'Attribute': 'Height', 'Value': '5.5'}},
{'Person': {'Name': 'Mary', 'Attribute': 'Weight', 'Value': '140'}}
]
How would I go about doing that?
I've managed the following, but it only seems to nest one dictionary:
betterlist = { 'Person' : i for i in listofdicts}
Any help would be appreciated. Thank you everyone.