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 metal
Recipients LeWiemann, gvanrossum, mark.dickinson, metal, rhettinger, tixxit
Date 2010-03-31.16:36:57
SpamBayes Score 3.1299376e-09
Marked as misclassified No
Message-id <1270053419.98.0.680647313809.issue1771@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2010-03-31 16:37:00metalsetrecipients: + metal, gvanrossum, rhettinger, mark.dickinson, LeWiemann, tixxit
2010-03-31 16:36:59metalsetmessageid: <1270053419.98.0.680647313809.issue1771@psf.upfronthosting.co.za>
2010-03-31 16:36:58metallinkissue1771 messages
2010-03-31 16:36:57metalcreate