Missing the functional mind set

Rainer Deyke root at rainerdeyke.com
Sat Mar 3 13:22:18 EST 2001


"Daniel Klein" <danielk at aracnet.com> wrote in message
news:mlb2at8ptrr7sh5dgq8qlk2201kquh6tfl at 4ax.com...
> 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])

This is equivalent to:

templist = [d[n] for n in range(len(d))]


But if you are indexing with integers from 0 to n, why are you using a
dictionary in the first place?


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list