This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author dtorp
Recipients LeWiemann, dtorp, gvanrossum, mark.dickinson, metal, rhettinger, tixxit
Date 2010-03-31.17:40:05
SpamBayes Score 0.00014739347
Marked as misclassified No
Message-id <1270057206.47.0.221084976966.issue1771@psf.upfronthosting.co.za>
In-reply-to
Content
> 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.
History
Date User Action Args
2010-03-31 17:40:06dtorpsetrecipients: + dtorp, gvanrossum, rhettinger, mark.dickinson, LeWiemann, tixxit, metal
2010-03-31 17:40:06dtorpsetmessageid: <1270057206.47.0.221084976966.issue1771@psf.upfronthosting.co.za>
2010-03-31 17:40:05dtorplinkissue1771 messages
2010-03-31 17:40:05dtorpcreate