Is there a fast way to generate a dict of the alphabet in Python?

Nope picture Nope · Jan 17, 2009 · Viewed 60.2k times · Source

I want to generate a dict with the letters of the alphabet as the keys, something like

letter_count = {'a': 0, 'b': 0, 'c': 0}

what would be a fast way of generating that dict, rather than me having to type it in?

Thanks for your help.

EDIT
Thanks everyone for your solutions :)

nosklo's solution is probably the shortest

Also, thanks for reminding me about the Python string module.

Answer

nosklo picture nosklo · Jan 17, 2009

I find this solution more elegant:

import string
d = dict.fromkeys(string.ascii_lowercase, 0)