sorting the list by inner elements

ketulp_baroda at yahoo.com ketulp_baroda at yahoo.com
Thu Mar 25 08:05:18 EST 2004


"Sean Ross" <sross at connectmail.carleton.ca> wrote in message news:<brg8c.18665$A_2.958214 at news20.bellglobal.com>...
> <ketulp_baroda at yahoo.com> wrote in message
> news:f046efac.0403240543.65a49ba1 at posting.google.com...
> > Hi, all
> >
> >  I want to sort the list,the form of my list is
> >
> >   name_city_list=[['jack','new york'],['mac','london'],['alice','paris']]
> >
> > all inner list has same format i.e first is name and second is city.
> > now I want to sort it by the second element of the inner list(by city
>  name).
> >
> > i.e after sorting my list should be like this
> >
> >   name_city_list=[['mac','london'],['jack','new york'],['alice','paris']]
> >
> > how can I do this,
> >
> > any way out ?
> 
> name_city_list.sort(lambda x, y: cmp(x[1],y[1]))

Hi,

This works !!! , thanks.
but I would like to know something that
i heard use of lambda function is not good !. So why it is not good,
or in when we should not use lambda function.

thank you again,



More information about the Python-list mailing list