[Tutor] Sorting a dictionary
Johan Geldenhuys
johan at accesstel.co.za
Fri Nov 4 09:09:26 CET 2005
Hi all,
In my new project I needed a dictionary with TCP/UDP port numbers as
keys and the service for that key as the value.
I got the info from the services file in Linux and compiled a dictionary
as I needed.
The only thing that I want to do is to sort the dictionary from the
smallest key number to the largest key number.
Example:
I have:
ser_port = {'4401': 'ds-srvr', \
'5427': 'sco-peer-tta', \
'4446': 'n1-fwp', \
'3734': 'synel-data', \
'4447': 'n1-rmgmt', \
'5745': 'fcopy-server', \
'5990': 'wbem-exp-https', \
'4026': 'as-debug', \
'3724': 'battlenet'}
I want:
ser_port = { '3724': 'battlenet', \
'3734': 'synel-data', \
'4026': 'as-debug', \
'4401': 'ds-srvr', \
'4446': 'n1-fwp', \
'4447': 'n1-rmgmt', \
'5427': 'sco-peer-tta', \
'5745': 'fcopy-server', \
'5990': 'wbem-exp-https'}
My dictionary comsists of a few thousand entries and it will not be fun
to do this manually. How do I sort the dictionary to read better/easier?
TIA,
BTW: If anybody wants this to use, please ask.
Johan
More information about the Tutor
mailing list