How to sort Python dict (dictionary)
26th September 2007
Sample script (copypasted from Well House Consultants training course):
click the PLAIN TEXT header for copy-pasteable version
- #!/usr/local/bin/python
- author = {"php":"Rasmus Lerdorf",\
- "perl":"Larry Wall",\
- "tcl":"John Ousterhout",\
- "awk":"Brian Kernighan",\
- "java":"James Gosling",\
- "parrot":"Simon Cozens",\
- "python":"Guido van Rossum"}
- langs = author.keys()
- langs.sort()
- for language in langs:
- print language,"is the child of",author[language]
You can also define the Python ksort() function similar to that found in PHP:
Read the rest of this entry »
Posted in Programming, Python | 1 Comment »
