Missing the functional mind set

Daniel Klein danielk at aracnet.com
Sat Mar 3 13:08:48 EST 2001


The purpose of this code is to return a list of dictionary values sorted by
key, resulting in 'templist'.

>>> d = {3: 'd', 2: 'b', 1: 'a', 0: 'z'}
>>> templist = []
>>> for n in range(len(d)):
	templist.append(d[n])

>>> templist
['z', 'a', 'b', 'd']

Of course when I have this in its best form, it will become a class method.

My question is, is there a 'functional' (or list comprehension) solution to
this? I don't seem to have a sufficient grasp of functional programming as yet.
I don't really want the 'complete' answer as I'd like to try to work it out for
meself. I guess I'm just looking for a 'push' in the right direction; maybe
just a hint to get that lightbulb to pop on over my head.

Note: this is _not_ a school assignment; this is for a real project I am doing
for my company.

Thanks,
Daniel Klein



More information about the Python-list mailing list