David Albert Torpey <[email protected]> added the comment:
> 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'].
That cmp function is nonsense and isn't even close to being correct:
>>> from random import shuffle
>>> for i in range(10):
... t = list(tree)
... shuffle(t)
... print sorted(t, cmp=lambda x, y: 1 if x in tree[y] else -1 if y in
tree[x] else 0)
['E', 'C', 'B', 'D', 'A']
['A', 'D', 'C', 'B', 'E']
['C', 'B', 'E', 'D', 'A']
['E', 'D', 'A', 'C', 'B']
['A', 'B', 'D', 'E', 'C']
['D', 'A', 'E', 'C', 'B']
['C', 'D', 'A', 'B', 'E']
['A', 'C', 'B', 'D', 'E']
['A', 'C', 'B', 'E', 'D']
['A', 'C', 'B', 'D', 'E']
> how to convert cmp to key really confused
> me and it surely need more typing time.
Just cut and paste the recipe. Simple.
----------
nosy: +dtorp
_______________________________________
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