Re: sorted() erraticly fails to sort string numbers

2009-04-30 Thread Paddy O'Loughlin
2009/4/30 Lie Ryan > container[:] = sorted(container, key=getkey) >> >> is equivalent to: >> >> container.sort(key=getkey) >> >> > Equivalent, and in fact better since the sorting is done in-place instead > of creating a new list, then overwriting the old one. Not when, as pointed out

Re: sorted() erraticly fails to sort string numbers

2009-04-30 Thread Lie Ryan
John Posner wrote: uuid wrote: I am at the same time impressed with the concise answer and disheartened by my inability to see this myself. My heartfelt thanks! Don't be disheartened! Many people -- myself included, absolutely! -- occasionally let a blind spot show in their messages to this li

Re: sorted() erraticly fails to sort string numbers

2009-04-28 Thread uuid
On 2009-04-28 16:18:43 +0200, John Posner said: Don't be disheartened! Many people -- myself included, absolutely! -- occasionally let a blind spot show in their messages to this list. Thanks for the encouragement :) BTW: container[:] = sorted(container, key=getkey) ... is equivalent

Re: Re: sorted() erraticly fails to sort string numbers

2009-04-28 Thread John Posner
uuid wrote: I am at the same time impressed with the concise answer and disheartened by my inability to see this myself. My heartfelt thanks! Don't be disheartened! Many people -- myself included, absolutely! -- occasionally let a blind spot show in their messages to this list. BTW: contai

Re: sorted() erraticly fails to sort string numbers

2009-04-28 Thread uuid
I am at the same time impressed with the concise answer and disheartened by my inability to see this myself. My heartfelt thanks! On 2009-04-28 10:06:24 +0200, Andre Engels said: When sorting strings, including strings that represent numbers, sorting is done alphabetically. In this alphabeti

Re: sorted() erraticly fails to sort string numbers

2009-04-28 Thread Andre Engels
On Tue, Apr 28, 2009 at 9:47 AM, uuid wrote: > I would be very interested in a logical explanation why this happens on > python 2.5.1: > > In order to sort an etree by the .text value of one child, I adapted this > snippet from effbot.org: > >> import xml.etree.ElementTree as ET >> >> tree = ET.pa

sorted() erraticly fails to sort string numbers

2009-04-28 Thread uuid
I would be very interested in a logical explanation why this happens on python 2.5.1: In order to sort an etree by the .text value of one child, I adapted this snippet from effbot.org: import xml.etree.ElementTree as ET tree = ET.parse("data.xml") def getkey(elem): return elem.findtext