Haskell can this:
['a'..'z']
In Python:
map(chr, range(97, 123))
I feel Python is something verbose. Have Python another easy way like Haskell?
Haskell can this:
['a'..'z']
In Python:
map(chr, range(97, 123))
I feel Python is something verbose. Have Python another easy way like Haskell?
from string import ascii_lowercase
L = list(ascii_lowercase)
A slightly more readable version without importing anything
alphabet = [chr(i) for i in range(ord('a'), ord('z') + 1)]
There is no generic way, because syntax [a..b]
in haskell uses special typeclass Enum, but there is no special magic methods or special syntax for enumeration in python.
Since you want it as a list, then you can do the following:
from string import ascii_lowercase
l = [i for i in ascii_lowercase]