Message102022
> 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. |
|
Date |
User |
Action |
Args |
2010-03-31 17:40:06 | dtorp | set | recipients:
+ dtorp, gvanrossum, rhettinger, mark.dickinson, LeWiemann, tixxit, metal |
2010-03-31 17:40:06 | dtorp | set | messageid: <1270057206.47.0.221084976966.issue1771@psf.upfronthosting.co.za> |
2010-03-31 17:40:05 | dtorp | link | issue1771 messages |
2010-03-31 17:40:05 | dtorp | create | |
|