Declare a new variable that is the key to your dict
from itertools import izip
nums = [1,18]
chars = ['a','d']
keys = ["num", "char"]
which gives a slightly more elegant solution, I think.
[dict(zip(keys,row)) for row in izip(nums,chars)]
It is definitely more elegant when there are more keys (which is why I started looking for this solution in the first place :)
If you want, this setting gives the same thing as a generator:
(dict(zip(keys,row)) for row in izip(nums,chars))
source
share