-2

Is there a built in list in python or some package that has a list of the alphabets? I would like to avoid a system such as

alphabets = ('a','b','c',.....)
4

2 回答 2

10

使用string.ascii_lowercase

>>> from string import ascii_lowercase
>>> ascii_lowercase
'abcdefghijklmnopqrstuvwxyz'
>>> list(ascii_lowercase)
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
于 2013-11-02T21:42:01.917 回答
3

您还可以进行列表理解:

>>> [chr(i) for i in range(97,97+26)]
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
于 2013-11-02T21:45:41.080 回答