Missing the functional mind set
Steve Purcell
stephen_purcell at yahoo.com
Mon Mar 5 03:03:35 EST 2001
Kirby Urner wrote:
> >The problem is that sorting a list can't be done in a functional way.
>
> Maybe you didn't see the first responder's solution:
>
> >>> d = {3: 'd', 2: 'b', 1: 'a', 0: 'z'}
> >>> templist = [d[n] for n in range(len(d))]
> >>> templist
> ['z', 'a', 'b', 'd']
>
> That's a good 2.0 and up solution.
Except that he wanted the keys sorted, and didn't claim that they would
always be consecutive integers in range(len(d)).
(in which case I'd go for 'map(d.get, range(len(d)))' anyway)
-Steve
--
Steve Purcell, Pythangelist
Get testing at http://pyunit.sourceforge.net/
Get servlets at http://pyserv.sourceforge.net/
"Even snakes are afraid of snakes." -- Steven Wright
More information about the Python-list
mailing list