Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"lsort -indices"

35 views
Skip to first unread message

ZB

unread,
Nov 6, 2007, 6:58:46 PM11/6/07
to
Another example:

set a {x u w a i e}
lsort -indices $a - gives: 3 5 4 1 2 0

set b [lsort $a] - gives: a e i u w x (properly sorted list)
lsort -indices $b - gives: 0 1 2 3 4 5 (properly ascending indices)

Pay attention, that before and after sorting the elements have different
indices.

Either there's something wrong - or I don't understand, how it should work
with "-indices" option. My assumption was, that it returns a list of
integers, which will reflect the order of elements AFTER the list will be
sorted. But, as you can see above, in unsorted list x has index 3, and in
the sorted it has (proper) index 5. "a" had index 1 (why?) - after sorting
it has (proper) index 0. In my opinion the indices should be exactly the
same, only their order should be changed. Am I wrong?

So, how does it work, actually?
--
ZB

ZB

unread,
Nov 6, 2007, 7:07:25 PM11/6/07
to
Dnia 06.11.2007 ZB <zbREMOVE_THIS@AND_THISispid.com.pl> napisał/a:

> So, how does it work, actually?

OK, false assumption: I understand. It does show, how it would like still
using CURRENT indices.
--
ZB

bill...@alum.mit.edu

unread,
Nov 6, 2007, 10:56:04 PM11/6/07
to
On Nov 6, 4:07 pm, ZB <zbREMOVE_THIS@AND_THISispid.com.pl> wrote:
> Dnia 06.11.2007 ZB <zbREMOVE_THIS@AND_THISispid.com.pl> napisa³/a:

>
> > So, how does it work, actually?
>
> OK, false assumption: I understand. It does show, how it would like still
> using CURRENT indices.
> --
> ZB

Actually, the indices returned ARE the indices of A in sorted order.
Like most Tcl built-in commands, lsort is non-destructive. It does not
sort the list supplied as its argument in place - rather it returns a
new list (if you do not use -indices) or the list of indices (if you
do) without changing the original list.

0 new messages