Is there a built in list in python or some package that has a list of the alphabet? [duplicate]

StackOverflow https://stackoverflow.com/questions/19747199

Вопрос

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',.....)
Это было полезно?

Решение

Use 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']

Другие советы

You can also do a list comprehension:

>>> [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']
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top