Missing the functional mind set
Kirby Urner
urner at alumni.princeton.edu
Sun Mar 4 13:53:13 EST 2001
Steve Purcell <stephen_purcell at yahoo.com> 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.
> >>> d = {3: 'd', 2: 'b', 1: 'a', 0: 'z'}
> >>> stuff = d.items()
> >>> stuff.sort()
> >>> map(lambda i: i[1], stuff)
> ['z', 'a', 'b', 'd']
>
>The second is probably more efficient.
>
>-Steve
Kirby
More information about the Python-list
mailing list