[Zope-dev] case insensitive sorts
Shane Hathaway
shane@digicool.com
Thu, 04 Jan 2001 09:35:48 -0500
Chris Withers wrote:
>
> Dieter Maurer wrote:
> >
> > Chris Withers writes:
> > > Andrew
> > > bart
> > > David
> > > sophie
> > > Wayne
> > Why in hell do you switch caseness for similar objects?
>
> Who said anything about objects? I was just talking about lists of
> strings and in general, people prefer sorting based on the character to
> take precedence over sorting based on the case of that character.
>
> Sadly, python's default sort does it the other way round :-(
This is not wrong. Again, if the default sort tried to sort
case-insensitively, it would yield incorrect results for existing code
that sorts lists of strings containing data rather than text. And
again, what you really want is a "textops" module that does something
like this:
def sort_strings(data):
sortable_data = list(map(lambda s: (lower(s), s), data))
sortable_data.sort()
return map(lambda s: s[1], sortable_data)
Shane