>>x
[',', ',', 'CHAPTER', 'Emma', 'I', 'I', 'VOLUME', 'Woodhouse',
'clever', 'handsome']
>>x=sorted([',', ',', 'CHAPTER', 'Emma', 'I', 'I', 'VOLUME', 'Woodhouse', 'clever', 'handsome'], key=str) x
[',', ',', 'CHAPTER', 'Emma', 'I', 'I', 'VOLUME', 'Woodhouse',
'clever', 'handsome']
>>>
what do i need to do? 4 867
On May 26, 9:46*pm, notnorweg...@yahoo.se wrote:
>x
[',', ',', 'CHAPTER', 'Emma', 'I', 'I', 'VOLUME', 'Woodhouse',
'clever', 'handsome']>>x=sorted([',', ',', 'CHAPTER', 'Emma', 'I', 'I', 'VOLUME', 'Woodhouse', 'clever', 'handsome'], key=str)
>x
[',', ',', 'CHAPTER', 'Emma', 'I', 'I', 'VOLUME', 'Woodhouse',
'clever', 'handsome']
what do i need to do?
x.sort(key=str.upper)
On Mon, May 26, 2008 at 10:46 PM, <no**********@yahoo.sewrote:
>>>x
[',', ',', 'CHAPTER', 'Emma', 'I', 'I', 'VOLUME', 'Woodhouse',
'clever', 'handsome']
>>>x=sorted([',', ',', 'CHAPTER', 'Emma', 'I', 'I', 'VOLUME', 'Woodhouse', 'clever', 'handsome'], key=str) x
[',', ',', 'CHAPTER', 'Emma', 'I', 'I', 'VOLUME', 'Woodhouse',
'clever', 'handsome']
>>>>
what do i need to do?
-- http://mail.python.org/mailman/listinfo/python-list
That's correct behavior for what you gave it. Example from http://www.python.org/doc/2.4.3/whatsnew/node12.html :
>>sorted('Monty Python') # any iterable may be an input
[' ', 'M', 'P', 'h', 'n', 'n', 'o', 'o', 't', 't', 'y', 'y']
It looks like it's sorting based on ASCII value which means all upper
case letters come before any lower case letter.
On May 27, 12:46 pm, notnorweg...@yahoo.se wrote:
what do i need to do?
Ideally, you need to read some introductory material and stop
offloading whatever the hell it is you're doing to this group.
Dan Bishop <da*****@yahoo.comwrote:
On May 26, 9:46*pm, notnorweg...@yahoo.se wrote:
>>x=sorted([',', ',', 'CHAPTER', 'Emma', 'I', 'I',
'VOLUME', 'Woodhouse', 'clever', 'handsome'], key=str)
>>x
[',', ',', 'CHAPTER', 'Emma', 'I', 'I', 'VOLUME', 'Woodhouse', 'clever', 'handsome'] what do i need to do?
x.sort(key=str.upper)
Or another option to consider:
>>import locale locale.setlocale(locale.LC_COLLATE, 'en')
'English_United States.1252'
>>print ', '.join(sorted(['CHAPTER', 'eu', 'Emma', 'I', 'I', 'VOLUME',
'Woodhouse', 'clever', 'handsome', '\xe9t\xe9'], key=locale.strxfrm))
CHAPTER, clever, Emma, été, eu, handsome, I, I, VOLUME, Woodhouse
Annoyingly strxfrm in Python 2.5 can't cope with unicode so if you go this
way you need to make sure that the strings are all encoded with the correct
encoding (which in this example is the 1252 at the end of the string
returned from setlocale) or define a new key function which applies the
correct encoding.
--
Duncan Booth http://kupuguy.blogspot.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jess Austin |
last post by:
hi,
I like the way that Python does lists, and I love the way it does
iterators. But I've decided I don't like what it does with iterators
of lists. Lists are supposed to be mutable sequences,...
|
by: Helge |
last post by:
I wonder how this can be accomplished:
I've got a list, containing several strings. The strings look like
this:
I would like to create one object for each item in the list, and the
name...
|
by: George Sakkis |
last post by:
Hi all,
I find the string representation behaviour of builtin containers
(tuples,lists,dicts) unintuitive in that they don't call recursively str()
on their contents (e.g. as in Java) :
...
|
by: Elijah Bailey |
last post by:
I want to sort a set of records using STL's sort() function,
but dont see an easy way to do it.
I have a
char *data;
which has size mn bytes where m is size of the record and
n is the...
|
by: alexhong2001 |
last post by:
Does "std::sort" work only with sequence containers, not associative
containers at all?
Among sequential containers, can it be used with "list", "queue" and other
sequence containers besides...
| |
by: Xah Lee |
last post by:
Sort a List
Xah Lee, 200510
In this page, we show how to sort a list in Python & Perl and also
discuss some math of sort.
To sort a list in Python, use the “sort” method. For example:
...
|
by: joesindel |
last post by:
So heres the deal...
I work for a company in which numbers are dropping. The owners created
a game where calling potential clients racks up points for crap like
basketball ticekts and such. The...
|
by: 7stud |
last post by:
I can't get the str() method to work in the following code(the last
line produces an error):
============
class test:
"""class test"""
def __init__(self):
"""I am init func!"""
self.num = 10...
|
by: Jason |
last post by:
Hi folks--
Basically, I have a pressing need for a combination of 5.2 "Sorting a
List of Strings Case-Insensitively" & 5.3 "Sorting a List of Objects
by an Attribute of the Objects" from the...
|
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,...
|
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...
| |
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,...
|
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 project—planning, coding, testing,...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |