On Apr 9, 4:04 am, Jason <[EMAIL PROTECTED]> wrote:
> 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!

HiJason,
Try  key= lambda x: x.attr.lower()
The above should calculate the key only once for the items to be
sorted rather than using cmp which calculates more than that.

- Paddy.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to