Sort list of dictionaries by key (case insensitive)

Stefan Behnel stefan_ml at behnel.de
Wed Jan 13 07:35:14 EST 2010


Peter Otten, 13.01.2010 13:25:
> >>> items = "Atem Äther ähnlich anders".split()
> >>> print " ".join(sorted(items, key=lambda s: s.lower()))

If you can make sure that 's' is either always a byte string or always a 
unicode string (which is good programming practice anyway), an unbound 
method can simplify (and speed up) the above, e.g.

     sorted(items, key=unicode.lower)

Stefan



More information about the Python-list mailing list