sorting question
Ksenia Marasanova
ksenia.marasanova at gmail.com
Wed Aug 10 06:15:13 EDT 2005
> class Node:
> def __init__(self, name, url, order, pid, id):
> self.name = name
> self.url = url
> self.order = order
> self.pid = pid
> self.id = id
> def __repr__(self):
> return self.url
> def mycmp(x,y):
> if x.pid == y.pid:
> if x.order != y.order:
> return cmp(x.order,y.order)
> return cmp(x.url,y.url)
> return cmp(x.pid,y.pid)
> a = Node('ham','/test/ham/',1,0,1)
> b = Node('eggs','/test/ham/eggs/',1,1,2)
> c = Node('bacon','/test/ham/bacon/',1,1,3)
> d = Node('spam','/test/ham/bacon/spam/',1,3,4)
>
> Does this work for you? I haven't tested it much.
Thank you for help :)
It doesn't work yet. The id's are not sequentional, so it fails when
id of the child is lower than id of the parent.
If I change the last line in mycmp from
return cmp(x.pid,y.pid)
to
return cmp(x.url,y.url) # almost the same cmp function I use
than your example work and I can't break it. But the real code
(hunderds of nodes) doesn't, and I can't yet find the node(s) that
cause it :(
--
Ksenia
More information about the Python-list
mailing list