473,836 Members | 1,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1794

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.low ercase)

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...@jedimi ndworks.comwrot e:
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.low ercase)
Thanks a lot!
Apr 9 '07 #4
On Apr 9, 2:29*am, "人言落日 天涯,望 天涯不见 " <kelvin....@gma il.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...@nos pam.nowire.orgw rote:
人言落日是 天涯,望极 天涯不见家 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(6 5,91))

/Martin

Apr 9 '07 #7
Michael Bentley <mi*****@jedimi ndworks.comwrot e:
>
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.low ercase)
Be careful here. If you change locale that will return all lowercase
letters not just 'a' to 'z'. For example:
>>import locale, string
locale.setloc ale(locale.LC_A LL, '')
'English_United Kingdom.1252'
>>print string.lowercas e
abcdefghijklmno pqrstuvwxyz
>>>
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.let ters[: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

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

Similar topics

20
3134
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 change. Does anyone have any insight? class c: def __init__(self): self.traits = 4 # number of list elements self.types = 3 # elements can be 0, 1, or 2
0
7114
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 "Russian doll" style of schema design, where the nested type is local and anonymous (not a separate global type). 2. A complex type has nested within it a simple type which is derived through restriction with at least one facet, again nested,...
1
8297
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 dropdown lists. If you change the selection of the left one (e.g. choose parentoption2), it should open up page2.htm in a popup window.
13
5747
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 hoping the clc crowd had some ideas for making it even simpler! In-lined below the full program (132 lines). It's a circular singular linked list of "cells" inspired by the one in Plauger's text
8
5122
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 types or std::vector<int>. So where I would use an int* and reallocate it from time to time in C, and randomly access it via , then I figure to copy the capacity and reserve methods, because I just need a growable array. I get to considering...
9
1416
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 also press a post button that post these six numbers into the database. My problem is that these six numbers need to be posted to the database from less to greatest, and all of my code is within the business tier class not the code behind class. ...
73
4651
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 endless loop in a line with: if a==b: print 'OK' I mean, it would be of much help to me on my way to understanding Python to know how such prefix code leading to an endless loop can look like and if it is eventually not possible to write such...
8
5543
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 into C#. Here is a simple function in OCaml that nests "n" applications of "f" around "x", with "n" defaulting to "n=2": let rec nest ?(n=2) f x = if n=0 then x else nest ~n:(n-1) f (f x) For example, "nest f x" gives "f(f(x))" and "nest...
55
6503
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 distribution). I do not want to use the unreliable rand() function, but I do not want to bloat my code with something as complex as MT either. I am just looking for a short code snippet that I can copy without worrying about licensing. The function should...
0
9820
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
10845
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10549
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10592
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7792
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6979
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5828
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4456
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4019
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.