Re: [Zope-dev] case insensitive sorts
Chris Withers writes:
Andrew bart David sophie Wayne Why in hell do you switch caseness for similar objects?
If you apply some naming conventions, such as "objects start with a Capital letter, verb with a lowercase letter", you may find Python's sorting order usefull. Dieter
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 :-( Chris
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
Shane Hathaway wrote:
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)
... Or better, you could pass a comparison function to sort() like Tres suggested. :-) Shane
Shane Hathaway wrote:
Shane Hathaway wrote:
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)
... Or better, you could pass a comparison function to sort() like Tres suggested. :-)
This is where this whole thread started ;-) We end up using a comparision function every time we call sort, which is messy and results in a lot of duplicated code... My suggestion was for the default sort function to change so that when you want the sorting that makes sense to humans, you'd just have to do: list.sort() ...and when you wanted sort as it is now, then you could something like: list.sort(lambda x, y: old_cmp(y,x)) But this thread has lost noth its ends, so to speak, so I shall duck out ;-) cheers, Chris
Chris Withers writes:
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? Maybe, I should have said subjects.
Your example strings seem to name persons. It is very strange (and should be punished, as it is by Python's default sort ;-)) to use caseness inconsistently for these same type subjects/objects/entities (whatever you like). I am not against an option to specify what comparison function should be used for sorting (when I would implement it, I would probably follow Python's sort interface and provide an optional function rather than have a collection of attributes specifying the sort order). However, I am against a change of the sort order in the *management interface* (unless I can easily switch back). The reason: I make sensible use of the ASCII based sort order and would not like to loose it. Dieter
participants (3)
-
Chris Withers -
Dieter Maurer -
Shane Hathaway