[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()
METAL XXX
report at bugs.python.org
Wed Mar 31 18:36:59 CEST 2010
METAL XXX <metal29a at gmail.com> 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 <report at bugs.python.org>
<http://bugs.python.org/issue1771>
_______________________________________
More information about the Python-bugs-list
mailing list