Re: a dict problem
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: a dict problem

From: Steven Bethard <steven.bethard@gmail.com>
Date: Sat May 28 2005 - 20:00:59 CEST

Benji York wrote:
> I'll extrapolate from your message that you want to get the values of
> the dict in sorted order. If so, here's how:
>
> >>> d = {'a': 1, 'b': 2, 'c':3}
> >>> d
> {'a': 1, 'c': 3, 'b': 2}
> >>> v = d.values()
> >>> v
> [1, 3, 2]
> >>> v.sort()
> >>> v
> [1, 2, 3]

Or in Python 2.4:

py> d = {'a': 1, 'b': 2, 'c':3}
py> sorted(d.values())
[1, 2, 3]
Received on Thu Sep 29 16:15:34 2005