[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Sorting dictionary tables by value
- From: Kevin Krumwiede <kjkrum@...>
- Date: Sun, 11 Nov 2007 19:42:55 -0800 (PST)
Thanks for your response. Instead of rewriting all my
code, I got the bright idea of simply copying my data
into another table for sorting and output. Something
like:
function GetSortedTable(tbl)
local meta = {};
for foo, bar in pairs(tbl) do
table.insert(meta, {key=foo, value=bar});
end
table.sort(meta, function(a,b) return a.value >
b.value; end);
return meta;
end
local sorted = GetSortedTable(someTable);
for idx, row in ipairs(sorted) do
-- something with row.key and row.value
end
--- manel <lista@fisi10.ciencias.uniovi.es> wrote:
> Hello
>
> table.sort only works with the numerical part of the
> table
> form 1 to #table (the *array* part). Your second
> approach
> is a possibility.
>
> I think this subject appeared in old posts in this
> list.
> You can also consult:
>
> http://lua-users.org/wiki/OrderedTable
>
> http://lua-users.org/wiki/OrderedTableSimple
>
>
> Manel.
>
>
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com