Tech stuff and info dump

python: generate a list of uppercase or lowercase letters in the alphabet

May 30th, 2010

To create a list of lower-case letters in the alphabet in python:

map(chr, range(97, 123))

To create a list of upper-case letters in the alphabet in python:

map(chr, range(65, 91))

Examples:

>>> map(chr, range(65, 91))
[‘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’]

>>> a=map(chr, range(97, 123))
>>> a
[‘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’]


Filed under: python,script
May 30th, 2010 16:59:09
4 comments

guest
September 8, 2010

just use

import string
string.uppercase
string.lowercase


soum
January 31, 2012

thans for this code!!


guset
February 21, 2013

can use :

import string
string.letters[:26]
string.letters[26:]


Shreyans
June 24, 2014

import string

a=string.ascii_lowercase
print a

For list :
letters=[i for i in string.ascii_lowercase]

Leave a Reply