egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

lsort - need two-pass sort :O

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
FallFromGrace
Voice


Joined: 28 Jul 2008
Posts: 17

PostPosted: Tue Aug 12, 2008 11:13 am    Post subject: lsort - need two-pass sort :O Reply with quote

i have a list with such elements:
{kelly 15 1}
{john 50 4}
{jack 80 2}
{bill 70 3}
{ann 30 2}
{james 100 1}

so i need to sort it, to get:
{john 50 4}
{bill 70 3}
{jack 80 2}
{ann 30 2}
{james 100 1}
{kelly 15 1}

with first sort by 3th value and second sort by 2th value..

maximum that i can get is a list sorted by 2th or 3th value... [lsort -index 1 or 2 -decreasing $list]

how to sort it again?
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Tue Aug 12, 2008 11:49 am    Post subject: Reply with quote

lsort uses a merge-sort, and depending on the merge-algorithm, you might be able to get away with something like this:

Code:
set newlist [lsort -index 2 -decreasing [lsort -index 1 -decreasing $list]]

_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
FallFromGrace
Voice


Joined: 28 Jul 2008
Posts: 17

PostPosted: Tue Aug 12, 2008 7:49 pm    Post subject: Reply with quote

it works ^^

tnx you )
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber