A function returns two lists which are logically mapped one-to-one. Suppose
name = ["facebook", "twitter", "myspace"]
hits = [4000, 2500, 1800]
Therefore, hits for facebook are 4000, twitter 2500, and myspace 2500.
I want to convert these two separate lists into a list of dictionaries like
[
{name: 'facebook',data: [4000]},
{name: 'twitter',data: [2500]},
{name: 'myspace',data: [1800]}
]
My solution to do this is:
data = [
{"name":l, "data":[v]}
for idx1, l in enumerate(labels)
for idx2, v in enumerate(values)
if idx1 == idx2
]
Is there a more elegant way of dealing with logical one-to-one mapping or is my solution precise?