Reputation: 1809
The lists have the same number of elements, and the names are unique. I wonder, how can I make a dict in one action.
This is my current code:
fees = [fee for fee in fees]
names = [name for name in names]
mdict = [
{'fees': fee[i], 'names': names[i]}
for i, val in enumerate(fees)]
Upvotes: 1
Views: 57
Reputation: 3822
You want this
{fees[i]:y[i] for i in range(len(fees))}
or more quite :
dict(zip(fees, names))
Upvotes: 1
Reputation: 78546
You can use zip
on both lists in a list comprehension:
mdict = [{'fees': f, 'names': n} for f, n in zip(fees, names)]
Upvotes: 3