[Tutor] General construction of alpha lists?

Karl Fast karl.fast at pobox.com
Tue Oct 21 23:42:06 EDT 2003


> Is there an easy way to specify a list that is simply letters in
> order, or do I have to write out
> 
> alpha = [ 'A', 'B', ... 'Z', 'a', 'b', ... 'z' ]

The string module defines various constants that have the characters
you want. If you do this in the shell you can see what's in these
constants.

  >>> import string
  >>> print string.uppercase
  ABCDEFGHIJKLMNOPQRSTUVWXYZ¦´¼¾ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ
  >>> print string.lowercase
  abcdefghijklmnopqrstuvwxyz¨µ¸½ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ
  >>> print string.printable
  0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&'()*+,-./:;<=>?@[\]^_{|}~

There are other constants too. Details in the string module docs.

I'm new to python myself, but this should do what you want.


--karl



More information about the Tutor mailing list