I am relatively new to Python, and I need some help to understand how the output is obtained for the following code:
keys = ['id', 'name', 'age']
values = [10, 'Ross', 19]
a_dict = {key:value for key in keys for value in values}
print(a_dict)
The output is:
{'id': 19, 'name': 19, 'age': 19}
I have tried nested loop too and I got the same output. I also tried interchanging key and value in the loop but there was no effect.
Can someone explain this please?
Edit:
I know how to get the output as
{'id': 10, 'name': 'Ross', 'age': 19}
I am only requesting an explanation for how the code I wrote works.. especially how the for loop works for the value part.