Need customised sort
bvdpoel at uniserve.com
bvdpoel at uniserve.com
Sat Apr 13 20:50:12 EDT 2002
Bengt Richter wrote:
>
> On Sat, 13 Apr 2002 12:19:35 -0700, bvdpoel at uniserve.com wrote:
>
> >
> >Yeah, I thought this would be easy...
> >
> >I have a list like this:
> >
> > [ [0, x, [0, y, [4, n] ...]
> >
> Is this what it appears to be? I.e., a linked list of [offset,event,link]
> rooted in a [] ? Thus:
Not quite. I missed a ']' and it should be [ [0,x], [0,y], [4,n]...].
Each list
element is a pair.
> [ + ]
> |
> +[0, x, +]
> |
> +[0, y, +]
> |
> +[4, n *?*]
>
> (*?* what goes here, or are you using len(element)<3 to indicate eol?)
>
> If it is a linked list, do you need that for fast insertions on the fly, or what?
> If not, why not [ [0,x], [0,y], [4,n] ...] or [ (0,x), (0,y), (4,n) ...] ?
>
> The sorting is going to be different, depending ;-)
> BTW, is there no cheap way to maintain desired order as you build/modify the list,
> so you won't need a sort per se?
>
I changed to a dict with the key the offset. So now I have things like:
dict = [ 0:[x,y], 4:[n] }
Of course this is all built on the fly. Nice thing about the dict method
is that
I don't have to worry about the sort problem, and internally it is
probably more
efficient.
Thanks.
--
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: bvdpoel at uniserve.com
WWW: http://users.uniserve.com/~bvdpoel
More information about the Python-list
mailing list