Why does this work in jython and not in python?

Roman Milner roman at speeder.org
Wed Jun 18 13:01:25 EDT 2003


I'm sorting a list of dictionaries based on a particular key. Using
the code below, the list gets sorted in jython, but not in python. I'm
using python 2.2.1 and jython 2.1.

I really appreciate any help.

^Roman

# if you run this with jython, you get a sorted list
# with python the list stays in the same order. Why?

tdict = [{'a':5}, {'a':3},{'a':4},{'a':2},{'a':1}]

def sort_func(one, two):
    return one['a'] < two['a']

print tdict
tdict.sort(sort_func)
print tdict




More information about the Python-list mailing list