473,396 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

Is there a simple function to generate a list like ['a', 'b', 'c', ...
'z']? The range() just can generate the numeric list.

Apr 9 '07 #1
10 1757

On Apr 9, 2007, at 3:29 AM, 人言落日是天涯,望极天涯不
见家 wrote:
Is there a simple function to generate a list like ['a', 'b', 'c', ...
'z']? The range() just can generate the numeric list.

import string
list(string.lowercase)

Apr 9 '07 #2
人言落日是天涯,望极天涯不见家 schrieb:
Is there a simple function to generate a list like ['a', 'b', 'c', ...
'z']? The range() just can generate the numeric list.
There is:
[ chr(i) for i in range(97, 123) ]

Thomas
Apr 9 '07 #3
On Apr 9, 4:35*pm, Michael Bentley <mich...@jedimindworks.comwrote:
On Apr 9, 2007, at 3:29 AM, 人言落日是天涯,望极天涯不

见家 wrote:
Is there a simple function to generate a list like ['a', 'b', 'c', ...
'z']? * The range() just can generate the numeric list.

import string
list(string.lowercase)
Thanks a lot!
Apr 9 '07 #4
On Apr 9, 2:29*am, "人言落日是天涯,望极天涯不见家 " <kelvin....@gmail.comwrote:
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
Apr 9 '07 #5
On Apr 9, 4:39*pm, Thomas Krüger <newsgro...@nospam.nowire.orgwrote:
人言落日是天涯,望极天涯不见家 schrieb:
Is there a simple function to generate a list like ['a', 'b', 'c', ...
'z']? * The range() just can generate the numeric list.

There is:
[ chr(i) for i in range(97, 123) ]

Thomas
Thanks you too! I'm a beginner of python.
Apr 9 '07 #6
map(chr,range(65,91))

/Martin

Apr 9 '07 #7
Michael Bentley <mi*****@jedimindworks.comwrote:
>
On Apr 9, 2007, at 3:29 AM, 人言落日是天涯,望极天涯不
见家 wrote:
>Is there a simple function to generate a list like ['a', 'b', 'c', ...
'z']? The range() just can generate the numeric list.


import string
list(string.lowercase)
Be careful here. If you change locale that will return all lowercase
letters not just 'a' to 'z'. For example:
>>import locale, string
locale.setlocale(locale.LC_ALL, '')
'English_United Kingdom.1252'
>>print string.lowercase
abcdefghijklmnopqrstuvwxyz
>>>
Apr 9 '07 #8
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.

Apr 9 '07 #9
Thomas[ chr(i) for i in range(97, 123) ]

Or with fewer magic numbers:

[chr(i) for i in range(ord('a'), ord('z')+1)]

Skip
Apr 9 '07 #10

On Apr 9, 2007, at 6:30 AM, Duncan Booth wrote:
Michael Bentley <mi*****@jedimindworks.comwrote:
>>
On Apr 9, 2007, at 3:29 AM, 人言落日是天涯,望极天涯不
见家 wrote:
>>Is there a simple function to generate a list like ['a', 'b',
'c', ...
'z']? The range() just can generate the numeric list.


import string
list(string.lowercase)
Be careful here. If you change locale that will return all lowercase
letters not just 'a' to 'z'. For example:
>>>import locale, string
locale.setlocale(locale.LC_ALL, '')
'English_United Kingdom.1252'
>>>print string.lowercase
abcdefghijklmnopqrstuvwxyz
Thanks, Duncan -- that would have eventually bitten me.

Apr 9 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: drs | last post by:
Hi, I am trying to find all lists of length x with elements a, b, and c. To this end, I have created the class below, but it is not quite working and I am having trouble figuring out what to...
0
by: mjcsfo | last post by:
I can't seem to find a reference nor any helpful threads on this topic. I've gotten the following error in two circumstances: 1. A complex type has nested within it another complex type, in the...
1
by: Joseph Barron | last post by:
Here is a SIMPLE problem that I'm trying to solve. It works in Netscape 6.2, but IE6 gives ""No such interface supported." Below are page1.htm and page2.htm . In page1.htm, there are two...
13
by: Michael B Allen | last post by:
Hi, I've tried to write the *simplest* memory allocator possible. I think it would be useful in many cases such as allocating memory on stack as a poor man's garbage collection perhaps. I was...
8
by: Ross A. Finlayson | last post by:
I'm trying to write some C code, but I want to use C++'s std::vector. Indeed, if the code is compiled as C++, I want the container to actually be std::vector, in this case of a collection of value...
9
by: Leon | last post by:
I have a webform in which when the user press generate button the form generate six unique ramdon numbers, the user can also type these six numbers in manually in any order. however, the user can...
73
by: Claudio Grondi | last post by:
In the process of learning about some deeper details of Python I am curious if it is possible to write a 'prefix' code assigning to a and b something special, so, that Python gets trapped in an...
8
by: Jon Harrop | last post by:
I am trying to learn C# and .NET programming in general but I am finding it very hard going. To start with, I'd like to translate some trivial functions from other languages that I am familiar with...
55
by: copx | last post by:
Can anyone point me to a simple, fast RRNG function to generate random ints within a specified range? It is important that each value within the range has the same probability (uniform...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.