How do you split a list of dictionaries and assign it to variables a and b to compare it? For example: How can I get results and assign them to a and b like below?
Problem:
results = [
{
"name": "Sarah",
"age": 45
},
{
"name": "Sarah",
"age": 18
}
]
Desired outcome:
a = {
"name": "John",
"age": 45
}
b = {
"name": "John",
"age": 18
}
This is my solution but I dont feel it is the right way to do it:
a = {}
b = {}
i = 0
for result in results:
if i == 0:
a = result
else:
b = result
i += 1
Thank you.