Sorting a List of Objects by an Attribute of the Objects Case-Insensitively

Jason elgrandchignon at gmail.com
Wed Apr 9 05:04:48 CEST 2008


Hi folks--

Basically, I have a pressing need for a combination of 5.2 "Sorting a
List of Strings Case-Insensitively" & 5.3 "Sorting a List of Objects
by an Attribute of the Objects" from the Python Cookbook.

My first guess isn't working:

import operator
def sort_by_attr(seq, attr):
     key=operator.attrgetter(attr)
     key=str.lower
     return sorted(seq, key)

...would much appreciate any guidance!



More information about the Python-list mailing list