Fate of lambda, Functional Programming in Python...
Reinhold Birkenfeld
reinhold-birkenfeld-nospam at wolke7.net
Fri Aug 20 16:37:07 EDT 2004
Jeff Sandys wrote:
> | > > Hi,all
> | > > I have a list like [(id,string),...],for example:
> | > >
> | > > [(1,'xxxxx'),(7,'ppppp'),(4,'gggggg'),...]
> | > >
> | > > I want to sort this list according to the id of each element.
> | > > After sorting,the list will become:
> | > >
> | > > [(1,'xxxxx'),(4,'gggggg'),(7,'ppppp')...]
> | >
> | > list.sort sorts tuples by first argument, then second &c. If you
> want
> | > a custom sort order, look at the decorate-sort-undecorate pattern.
> |
> | Or if you want to sort only on your Id, use a lambda:
> | l.sort(lambda x,y: cmp(x[0],y[0]))
> |
> | To force sorting on just the nth element of the tuples, replace 0
> with
> | n in the above.
> |
>
> I think that lambda should be unlimited and expanded. It already has
> the
> colon, block delimiter, so allow lambda to be a multistatement and
> multiline
> indented block!
So in what point exactly is this different from a def(), then?
Reinhold
--
Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows
mitbrächte, wäre das bedauerlich. Was bei Windows der Umfang eines
"kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk.
-- David Kastrup in de.comp.os.unix.linux.misc
More information about the Python-list
mailing list