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

Re: sorted() erraticly fails to sort string numbers

2009-04-30 Thread Paddy O'Loughlin
2009/4/30 Lie Ryan lie.1...@gmail.com 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

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

Re: sorted() erraticly fails to sort string numbers

2009-04-28 Thread Andre Engels
On Tue, Apr 28, 2009 at 9:47 AM, uuid m8r-r1c6...@mailinator.com 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

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 andreeng...@gmail.com said: When sorting strings, including strings that represent numbers, sorting is done

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:

Re: sorted() erraticly fails to sort string numbers

2009-04-28 Thread uuid
On 2009-04-28 16:18:43 +0200, John Posner jjpos...@snet.net 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)