generating a liste of characters

Vlastimil Brom vlastimil.brom at gmail.com
Wed Dec 3 09:39:11 EST 2008


2008/12/3 Yves Dorfsman <yves at zioup.com>:
> 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.
>
>
>
> Yves.
> http://www.sollers.ca/blog/2008/swappiness
> http://www.sollers.ca/blog/2008/swappiness/.fr
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

If you want tu use it generaly an any characters, maybe ord() can make
it a bit simpler:
>>> map(unichr, range(ord("a"), ord("z")))
[u'a', u'b', u'c', u'd', u'e', u'f', u'g', u'h', u'i', u'j', u'k',
u'l', u'm', u'n', u'o', u'p', u'q', u'r', u's', u't', u'u', u'v',
u'w', u'x', u'y']
>>>

otherewise see the string module with some predefined ranges.

hth,
  vbr



More information about the Python-list mailing list