[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2010-03-31 Thread METAL XXX

METAL XXX  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 
<http://bugs.python.org/issue1771>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2010-03-31 Thread METAL XXX

METAL XXX  added the comment:

Sorry I ripped the code from a mess and I forget the tree is "leaflized" as

tree = {
  'A': set(['B', 'C', 'D', 'E']),
  'B': set(['D', 'E']), 
  'C': set(),
  'D': set(),
  'E': set(),
}

I don't want to talk about the actual problem. I think sometime 
it's hard to give an "absolute" weight value as key, for this example,
is the relationship in graph. Then user have to "Copy and paste the recipe" to 
get a cmp function which should be already there. We are
all adults here, why don't SIMPLELY tell the newbie don't use cmp() use key() 
unless you know what you are doing.


Thanks for reply.

--

___
Python tracker 
<http://bugs.python.org/issue1771>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1771] Remove cmp parameter to list.sort() and builtin.sorted()

2010-07-20 Thread METAL XXX

METAL XXX  added the comment:

Shame on me, after a long time I realized the problem referenced in my old post 
(http://bugs.python.org/msg102019) was actually topological sorting. It can't 
be done by Python's sort(), which doesn't support partial order. Trying to use 
cmp parameter is completely wrong. And cmp would mislead people like me to sort 
a partial order, evil! Now I'm absolutely agree with gone of cmp, viva Raymond 
Hettinger!

--

___
Python tracker 
<http://bugs.python.org/issue1771>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2333] Backport set and dict comprehensions

2010-08-04 Thread METAL XXX

METAL XXX  added the comment:

How about fixing set.__repr__ ?

--
nosy: +metal

___
Python tracker 
<http://bugs.python.org/issue2333>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com