How to generate an array (a list) of the alphabet letters in Python

4 Answers

0 votes
import string

chars = list(string.ascii_lowercase)

print(chars)

'''
run:

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

'''

 



answered Mar 24, 2017 by avibootz
edited Mar 24, 2017 by avibootz
0 votes
import string

chars = list(string.ascii_lowercase)

for ch in chars:
    print(ch, end=" ")

'''
run:

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 

'''

 



answered Mar 24, 2017 by avibootz
0 votes
chars = list(map(chr, range(97, 123)))

for ch in chars:
    print(ch, end=" ")

'''
run:

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

'''

 



answered Mar 24, 2017 by avibootz
edited Mar 25, 2017 by avibootz
0 votes
chars = list(chr(i) for i in range(ord('a'), ord('z')+1))

for ch in chars:
    print(ch, end=" ")

'''
run:

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

'''

 



answered Mar 25, 2017 by avibootz

Related questions

2 answers 265 views
3 answers 195 views
2 answers 182 views
2 answers 191 views
2 answers 179 views
3 answers 338 views
1 answer 199 views
...