Reputation: 135
is there a way to zip a list with a list of lists? So for example you have the two lists:
lst1 = ['food', 'drinks', 'sports']
lst2 = [['hamburger', 'beer', 'football'], ['cheeseburger', 'wine', 'tennis']]
And then as a result u would get:
[{'food':'hamburger', 'drinks':'beer', 'sports':'football'},
{'food':'cheeseburger', 'drinks':'wine', 'sports':'tennis'}]
Is there a way to do this?
Upvotes: 1
Views: 73
Reputation: 57033
Combine dictionary construction and list comprehension:
[dict(zip(lst1, l)) for l in lst2]
Upvotes: 3