Thanks, Danny.

You see, I didn't put all the keys and values in the dicionary manually. It was generated while parsing a file with some Python code, that's why the dict is not in order. I just want to do it to read easier and look something up.

How will I then put my dict together again after sorting the items, so that the keys will follow from small to large?

Johan

Danny Yoo wrote:
  
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'}
    

Hi Johan,

Just as a quick side note: all those continuation characters '\' at the
end of those lines are unneccessary --- Python knows that there's more to
the line because of it's in the middle of a dictionary definition.  So you
can clean things up slightly by doing:

###########################
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',
}
###########################

Everything lines up nicely, and there's a little less line noise.  *grin*

We can even leave a trailing comma on the last key-value pair, just to
make adding more entries into the list easier, as we've done for the
'3724' entry.


I hope this helps!


  
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to