Problem in Dictionaries
Terry Reedy
tjreedy at udel.edu
Wed Mar 2 11:44:38 EST 2005
"Glauco Silva" <gbcs1978 at hotmail.com> wrote in message
news:BAY19-F1966B61A99BFFA643C9965DD590 at phx.gbl...
>I would like to know if the dictionary can sort with a function that i
>give to then!
No. You have to either make a list of key,value items and sort that,
possibly with a cmp or key parameter
items = d.items()
items.sort(()
or write or find a sorted_dict class (Google may help). In most
applications, people find that they only need a sorted listing of a dict
occasionally, so they just use the fast builtin dict and the fast builtin
list sort when needed.
Terry J. Reedy
More information about the Python-list
mailing list