[Tutor] list sorting problem (help!)
Erik Price
erikprice@mac.com
Mon, 9 Sep 2002 08:47:43 -0400
On Sunday, September 8, 2002, at 07:41 AM, Thomi Richards wrote:
> ok, i have a problem. i have a list, like this:
>
> ['email me','My programs','Web Design','Web Hosting']
>
> and i want to sort them, so i can say something like "the link 'My
> programs' should ALWAYS appear at the top". i thought I'd use a
> weighting system, so the 'My programs' list item would be weighted 0,
> and so always appear at the top. the next one would be '1', then '2',
> etc. etc. etc. i could give 'contact me' a weighting of 999, so it
> would
> always appear at the bottom.
>
> could i ask some of you python experts to make me a simple procedure
> which would do this?? It's for a CGI, which has to load every page, so
> the emphasis should be on minimal size and speed.. thanks.
If you are using a weighting system, then a Dictionary would seem to be
a good choice. I think it was on this list a few months back that one
or more of the resident gurus pronounced:
"When you find yourself thinking in terms of associations between
values, such as name and definition or item and ranking (etc), you
probably want a Dictionary." (not an exact quote but something like
that)
Dictionary lookups are supposedly pretty fast too.
Erik
--
Erik Price
email: erikprice@mac.com
jabber: erikprice@jabber.org