data_garden data_garden - 1 month ago 7
Python Question

Python - Populate a dictionary with list items

If a create a

dictionary
in this fashion:

output = {'playlist':{}}


having a
list
like this:

tracks = [u'No Surprises', u'Oceans', u'Up in Flames']


and with

count = 0


I would like to populate the
key
playlist
with all
tracks
items
as
keys
with
0 value
, like this:

output = {'playlist':{
'No Surprises': 0,
'Oceans': 0,
'Up in Flames': 0}}


how do I do that?

Answer
output = {'playlist':{track: count for track in tracks}}