Reputation: 99
Here I'm creating a 2D list where in for every element i have another dictionary defined. This is how i am using that function :
b = [[get_dict(x,y) for x in range(a)] for y in range(b)]
where the get_dict function brings the dictionary for that particular point eg.b[1][1]
I want to have this in a 2D dictionary instead of list which looks like
{ 0 : { 0 : get_dict(0,0)
{ 1 : get dict(0,1)
.....
}
{1: { 0: get_dict(1,0)
...
}
Upvotes: 2
Views: 95
Reputation: 3174
my_dict = {x: {y: get_dict(x, y) for y in range(b)} for x in range(a)}
Upvotes: 3