I have a list of dictionaries that look like this:
list_dict = [{"name": "joe", "dob": "01-01-2000"}, {"name": "jane", "dob": "02-01-2000"}, {"name": "jim", "dob": "03-01-2000"}]
I want to combine these into a large dictionary with a list of dictionaries like this:
{"people": [{"name": "joe", "dob": "01-01-2000"}, {"name": "jane", "dob": "02-01-2000"}, {"name": "jim", "dob": "03-01-2000"}]}
I think this is possible with list comprehension but when I try that, I get an error:
“ValueError: too many values to unpack (expected 2)”
How do I turn the list of dictionaries into a dict[list[dict]]?:
{"people": [{"name": "joe", "dob": "01-01-2000"}, {"name": "jane", "dob": "02-01-2000"}, {"name": "jim", "dob": "03-01-2000"}]}
It does not necessarily have to be through list comprehension
Thank you
d = {'people': list_dict}
…!?♦
I was trying to do list comprehension but wasn’t necessarily saying it had to be done that way. Wasn’t sure if it was even possible. @deceze, your first comment worked. Thank you