Newbie Questions: Swithing from Perl to Python

Todd Stephens huzzah at tampabay.rr.com
Sat Oct 25 22:30:53 EDT 2003


On Sat, 25 Oct 2003 22:07:13 -0400, Robert Brewer wrote:

>>>> myhash = {'a': 1, 'b': 2, 'c': 3}
>>>> myhash
> {'a': 1, 'c': 3, 'b': 2}
>>>> sortedKeys = myhash.keys()
>>>> sortedKeys.sort()
>>>> for eachKey in sortedKeys:
> ... 	print "%s = %s\n" % (eachKey, myhash[eachKey]) ...
 
Excellent.  I was laboring under the incorrect assumption that dictionary
keys could not be sorted.  Guess I have quite a bit more reading-up to do
on dictionaries.

-- 
Todd Stephens




More information about the Python-list mailing list