[Python-Dev] Re: other "magic strings" issues

Michael Hudson mwh at python.net
Tue Nov 11 06:40:02 EST 2003


David Eppstein <eppstein at ics.uci.edu> writes:

>> ...and we're back to wishing for a way to pass a nonlambda-callable.  E.g.
>> a string-related example would be "order the strings in list lotsastrings 
>> (which may be all plain strings, or all unicode strings, on different calls 
>> of this overall function) in case-insensitive-alphabetical order".  In 2.4 
>> _with_ the string module that's a snap:
>> 
>> lotsastrings.sort(key=string.upper)
>
> Is that really alphabetical?  It seems like it orders them based on the 
> ordinal value of the characters, which doesn't work so well for unicodes.
> The last time I needed this I couldn't figure out how to get a 
> reasonable case-insensitive-alphabetical order in pure python, so I used 
> PyObjC's NSString.localizedCaseInsensitiveCompare_ instead; a pure 
> Python solution that works as well as that one would be welcome.

The locale module has some things in this direction -- strxfrm and
strcoll, maybe? -- but I don't know what they do with unicode & doubt
they even exist on OS X.

Cheers,
mwh

-- 
  Do I do everything in C++ and teach a course in advanced swearing?
         -- David Beazley at IPC8, on choosing a language for teaching



More information about the Python-Dev mailing list