Reputation: 1
Right now I have a list of words and numbers:
List = [("purple", 8), ("orange", 2),...]
I want to make this into a dictionary:
Dictionary = [{"word":" purple", "number":8}, ...]
How do I go about this? Thanks in advance for any help
Upvotes: 0
Views: 66
Reputation: 46533
In [3]: [{'word': x, 'number': y} for x, y in List]
Out[3]: [{'word': 'purple', 'number': 8}, {'word': 'orange', 'number': 2}]
Though most probably you want this:
In [4]: dict(List)
Out[4]: {'orange': 2, 'purple': 8}
Upvotes: 4
Reputation: 7555
Dictionary = [{"word": word, "number": number} for word, number in List]
Upvotes: 1