generating a liste of characters

Matt Nordhoff mnordhoff at mattnordhoff.com
Fri Dec 5 02:23:33 EST 2008


This is a slightly old post, but oh well...

Shane Geiger wrote:
> import string
> alphabet=list(string.letters[0:26])
> print alphabet

Most of the string module's constants are locale-specific. If you want
the ASCII alphabet instead of the current language's, you need to use
string.ascii_{letters,lowercase,uppercase}.

> Yves Dorfsman wrote:
>> Is there any built in way to generate a list of characters, something
>> along the line of range('a'-'z') ?
>>
>> Right now I am using:
>>
>>   chars  = [ chr(l)  for l in range(0x30, 0x3a) ] # 0 - 9
>>   chars += [ chr(l)  for l in range(0x41, 0x5b) ] # A - Z
>>   chars += [ chr(l)  for l in range(0x61, 0x7b) ] # a - z
>>
>> Is there a better, more straight forward way of doing that ?
>>
>>
>>
>> Thanks.
-- 



More information about the Python-list mailing list