Is there a simple function to generate a list like ['a', 'b', 'c', ... 'z']?

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Mon Apr 9 09:08:06 EDT 2007


On Mon, 09 Apr 2007 01:43:11 -0700, 7stud wrote:

>> Is there a simple function to generate a list like ['a', 'b', 'c', ...
>> 'z']?   The range() just can generate the numeric list.
> 
> Not very simple, but how about a list comprehension:
> 
> import string
> 
> lst = [char for char in string.letters[:26] ]
> print lst

Anytime you write a list comp like [x for x in thing] that should be a
warning that you shouldn't be writing a list comp.

lst = list(string.letters[:26])


-- 
Steven.




More information about the Python-list mailing list