Sorting a List of Objects by an Attribute of the Objects Case-Insensitively
Jason
elgrandchignon at gmail.com
Tue Apr 8 23:04:48 EDT 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