It looks like you're new here. If you want to get involved, click one of these buttons!
local a = {} a["1"] = 1 a["2"] = 2 a["3"] = 3 a["16"] = 4 a["26"] = 5 a["28"] = 6 local b = {} b[1] = 1 b[2] = 2 b[3] = 3 b[16] = 4 b[20] = 5 b[23] = 6 b[26] = 7 b[28] = 8 local a2 = {} a2["1"] = 1 a2["2"] = 2 a2["3"] = 3 a2["4"] = 4 a2["5"] = 5 a2["6"] = 6 local b2 = {} b2[1] = 1 b2[2] = 2 b2[3] = 3 b2[4] = 4 b2[5] = 5 b2[6] = 6 local function printTable(table) local i, j for i, j in pairs(table) do print (i,":", j) end print ("=========") end printTable(a) 2 : 2 3 : 3 26 : 5 16 : 4 28 : 6 1 : 1 ========= -- ****************************************** -- This is where I would like more control -- ****************************************** printTable(b) 1 : 1 2 : 2 3 : 3 26 : 7 23 : 6 20 : 5 28 : 8 16 : 4 ========= printTable(a2) 2 : 2 3 : 3 4 : 4 5 : 5 6 : 6 1 : 1 ========= printTable(b2) 1 : 1 2 : 2 3 : 3 4 : 4 5 : 5 6 : 6 ========= |
Comments
http://www.giderosmobile.com/forum/discussion/2244/how-to-output-pairs-in-order-#Item_5
in your example how could you access a specific recipe?
In my case (a calendar) I would like to be able to do :
print (calendar[ 2013 ] [ 01 ] [ 24 ] ["status"])
That's why I would like to avoid having the key and the value on the same level.
Yes kind of calendar so that's why it's important for me to keep using numerical keys and why I have non-consecutive integer keys in my table.
I have some troubles to see how I could apply it to a calendar example, access easily to a specific day without having to find the corresponding id in the values instead of having access through a numerical key.
Would you have a very simple example to share for the following?
thank you
This way you could also sort the sortedDays table as you wish also. For example:
https://github.com/Yonaba/Moses/blob/master/docs/moses.md
Likes: vovanich