How do I create a dictionary with keys from a list and values defaulting to (say) zero?

Viewed 242966

I have a = [1,2,3,4] and I want d = {1:0, 2:0, 3:0, 4:0}

d = dict(zip(q,[0 for x in range(0,len(q))]))

works but is ugly. What's a cleaner way?

5 Answers
Related