[Tutor] General construction of alpha lists?

Clay Shirky clay at shirky.com
Tue Oct 21 21:42:46 EDT 2003


So I have this bit of code:

class_groups = [ 'A', 'B', 'C', 'D', 'E' ]

while class_groups:
      next = random.choice( range( len(class_groups) ))
      print class_groups[next]
      class_groups[next:next+1] = []

which will give me some random permutation of the items in the list
class_groups.

Next stop, making it possible to generate an alphabetical list, based on the
array number. I'd like to do something like

class_groups = range(12)

and then have it print from A through L. 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' ]

Thanks

-clay




More information about the Tutor mailing list