有没有快速的方式来生成Python中的字母表? [英] Is there a fast way to generate a dict of the alphabet in Python?

查看:194
本文介绍了有没有快速的方式来生成Python中的字母表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用字母表中的字母生成一个字母,例如:

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}

生成这个dict的方式,而不是我输入的方式?

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

感谢您的帮助。

编辑

感谢大家的解决方案:)

EDIT
Thanks everyone for your solutions :)

nosklo的
解决方案可能是最短的

另外,感谢提醒我有关Python <一个href =http://docs.python.org/library/string.html =noreferrer> string 模块。

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

推荐答案

我发现这个解决方案更加优雅:

I find this solution more elegant:

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

这篇关于有没有快速的方式来生成Python中的字母表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆