METAL XXX <[email protected]> added the comment:
I have a tree:
A
/ \
B C
/ \
D E
which is implemented as a dict
tree = {
'A': set(['B', 'C']),
'B': set(['D', 'E']),
'C': set(),
'D': set(),
'E': set(),
}
I want to sort the nodes.
and I don't know how to write a key function for sort() in this situation
so I write a cmp function:
sorted(tree, cmp=lambda x, y: 1 if x in tree[y] else -1 if y in tree[x] else 0)
and it gets ['A', 'C', 'B', 'E', 'D'].
how to convert cmp to key really confused me and it surely need more typing
time.
so I disagree the removal
----------
nosy: +metal
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue1771>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com