Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: how to print range a-z?

People also ask

How do I get a list of letters in Python?

range() and ord() ord() is practically the reverse of chr() because it converts characters into its ASCII counterpart. We'll use ord() as the arguments of range() to make a list of lowercase alphabets. We loop every output of range() and convert them into lowercase alphabet using chr() .


>>> import string
>>> string.ascii_lowercase[:14]
'abcdefghijklmn'
>>> string.ascii_lowercase[:14:2]
'acegikm'

To do the urls, you could use something like this

[i + j for i, j in zip(list_of_urls, string.ascii_lowercase[:14])]

Assuming this is a homework ;-) - no need to summon libraries etc - it probably expect you to use range() with chr/ord, like so:

for i in range(ord('a'), ord('n')+1):
    print chr(i),

For the rest, just play a bit more with the range()


Hints:

import string
print string.ascii_lowercase

and

for i in xrange(0, 10, 2):
    print i

and

"hello{0}, world!".format('z')

for one in range(97,110):
    print chr(one)