generating a liste of characters

James Mills prologic at shortcircuit.net.au
Wed Dec 3 09:27:19 EST 2008


On Thu, Dec 4, 2008 at 12:18 AM, Yves Dorfsman <yves at zioup.com> 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 ?

>>> from string import ascii_letters, digits
>>> chars = ascii_letters + digits
>>> chars
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
>>>

cheers
James

-- 
--
-- "Problems are solved by method"



More information about the Python-list mailing list