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

前端 未结 11 1844
终归单人心
终归单人心 2020-12-23 13:05

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

11条回答
  •  粉色の甜心
    2020-12-23 13:47

    There's this too:

    import string
    letter_count = dict((letter, 0) for letter in string.ascii_lowercase)
    

提交回复
热议问题