Q: sort's key and cmp parameters
Paul Rubin
http
Sat Oct 3 03:28:36 EDT 2009
Paul Rubin <http://phr.cx@NOSPAM.invalid> writes:
> Example comparison function:
>
> def compare(tree1, tree2):
> c = cmp(tree1['value'], tree2['value'])
> if c != 0: return c
> c = cmp(tree1['left'], tree2['left'])
> if c != 0: return c
> return cmp(tree1['right'], tree2['right])
Sorry, meant recursive comparison.
def compare(tree1, tree2):
c = cmp(tree1['value'], tree2['value'])
if c != 0: return c
c = compare(tree1['left'], tree2['left'])
if c != 0: return c
return compare(tree1['right'], tree2['right])
More information about the Python-list
mailing list