The function returns two lists that are logically displayed one to one . Let be
name = ["facebook", "twitter", "myspace"] hits = [4000, 2500, 1800]
Thus, the hits for facebook are 4000, twitter 2500 and myspace 2500.
I want to convert these two separate lists to a list of dictionaries , for example
[ {name: 'facebook',data: [4000]}, {name: 'twitter',data: [2500]}, {name: 'myspace',data: [1800]} ]
My solution for this:
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 to deal with one-to-one logical matching, or is my exact solution?
source share