Case-Insensitive Sorting of Multi-Dimensional Lists

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Fri Jun 8 17:39:32 CEST 2007


In <1181316575.800182.167640 at m36g2000hse.googlegroups.com>, mosscliffe
wrote:

> I have tried the following, for a one dimensional list and it works,
> but I can not get my head around this lambda. How would this be
> written, without the lamda ?

Well ``lambda``\s are just anonymous functions so you can write it with a
named function of course.

> mylist = ['Fred','bill','PAUL','albert']
> 
> mylist.sort(key=lambda el: el.lower())

So this becomes:

def keyfunc(el):
    return el.lower()

mylist.sort(key=keyfunc)

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list