Sortin dictionaries in python

costas at springmail.com costas at springmail.com
Tue Mar 13 11:47:26 EST 2001


Is there a simple way to sort a dictionary? It seems the only way to
do this is by indirectly creating  a sorted list.

And while on the topic of sorting lists. I tried sorting a list and
wanted to to pass a compare function to the list.sort() method. The
documentaion gives no example.

import string

x=['a','c','B']

def ignoreCase(left, right):
     if string.upper(left) < string.upper(right):
         return -1
     else:
         return 1

x.sort(ignoreCase(left, right))


But I get a message that left and right dont exist. How does one
define the compare function?

TIA

Costas



More information about the Python-list mailing list