# Retrieving data from a list, based on another sorted list

**URL:** <https://community.thunkable.com/t/retrieving-data-from-a-list-based-on-another-sorted-list/1365355>\
**Category:** Questions about Thunkable X\
**Tags:** beginner\
**Created:** [June 26, 2021, 12:50pm UTC](https://community.thunkable.com/t/retrieving-data-from-a-list-based-on-another-sorted-list/1365355 "2021-06-26T12:50:44Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mimostel](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/mimostel/32/107661_2.png) [@mimostel](https://community.thunkable.com/u/mimostel)\
**Post date:** [June 26, 2021, 12:50pm UTC](https://community.thunkable.com/t/retrieving-data-from-a-list-based-on-another-sorted-list/1365355/1 "2021-06-26T12:50:44Z")

</div>

Hello thunkers.  
Today im here for the following issue:  
I will simplify things to focus only on result, so lets say ill generate 2 lists, as in image below.  
After generating, because were generated in the same time, i will know exactly that the 3rd value in list1 will be “1,3” , and the same 3rd value in list2 will be “c”  
But the issue occurs after il want list1 to be sorted.  
If all values in list1 are different, all works just fine, using “first occur” in list1 to find correspondent value in list2. But if theres more than 1 value similar in list1, “first occurence” wont do the job.  
Ill attach an image to understand my issue better.

 ![screen](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/2/82ebff350096fb38195d5635a0b0d79a57441036.png)  
Hoping i made myself clear, thank you for providing me an workaround 🙂

---

<div class="post-metadata">

**Author:** ![overturner](https://avatars.discourse-cdn.com/v4/letter/o/53a042/32.png) [@overturner](https://community.thunkable.com/u/overturner)\
**Post date:** [June 26, 2021, 1:04pm UTC](https://community.thunkable.com/t/retrieving-data-from-a-list-based-on-another-sorted-list/1365355/2 "2021-06-26T13:04:40Z")

</div>

hi @mimostel I am not that great at list sorting but one thing i can notice is here  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/3/d/3d62a1fe7a50185a7b23beaed040dbbbfd2e9ae0.png)  
In the of object Section There is nothing  
I dont think thats how the block works.  
Correct me if I am wrong

---

<div class="post-metadata">

**Author:** ![mimostel](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/mimostel/32/107661_2.png) [@mimostel](https://community.thunkable.com/u/mimostel)\
**Post date:** [June 26, 2021, 1:05pm UTC](https://community.thunkable.com/t/retrieving-data-from-a-list-based-on-another-sorted-list/1365355/3 "2021-06-26T13:05:46Z")

</div>

ignore that… was only an example… imagine that there is a variable name 🙂 (just like in the next blocks

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [June 26, 2021, 1:06pm UTC](https://community.thunkable.com/t/retrieving-data-from-a-list-based-on-another-sorted-list/1365355/4 "2021-06-26T13:06:26Z")

</div>

You can create a single list of objects. The object has two properties (value1, vlaue2)

Now you can sort or manipulate and the order will be the same.

---

<div class="post-metadata">

**Author:** ![mimostel](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/mimostel/32/107661_2.png) [@mimostel](https://community.thunkable.com/u/mimostel)\
**Post date:** [June 26, 2021, 1:09pm UTC](https://community.thunkable.com/t/retrieving-data-from-a-list-based-on-another-sorted-list/1365355/5 "2021-06-26T13:09:16Z")

</div>

Fortunatly, list1 and list2 are properties of the same object (as you see in block2)  
So if i sort list1, list2 will have the same order based on list 1 ? this simplify things alot…  
Thank you very much

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [June 26, 2021, 1:11pm UTC](https://community.thunkable.com/t/retrieving-data-from-a-list-based-on-another-sorted-list/1365355/6 "2021-06-26T13:11:48Z")

</div>

Yes, when they are in an object they will have the same sorting.

---

<div class="post-metadata">

**Author:** ![mimostel](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/mimostel/32/107661_2.png) [@mimostel](https://community.thunkable.com/u/mimostel)\
**Post date:** [June 26, 2021, 1:20pm UTC](https://community.thunkable.com/t/retrieving-data-from-a-list-based-on-another-sorted-list/1365355/7 "2021-06-26T13:20:13Z")

</div>

But how do i retrieve “#” - index of list1`s value to apply in my example for list2 ? (that will be the same, as you said … Maybe ill need a new variable to store as a loop this ?

later edit:  
… something like this…

 ![screen](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/7/d78996511f42607a189d92d9fcc8eaa0819b6ad4.png)

… ill test it as soon as ill get home…  
Thank you again

Latwer, after testing.  
@muneer , i tested and it doesnt work. Maybe the lists as property of the same object are sorted togheter as i sort one list, but using a variable “contor” to keep index of list1 to retrieve value from list2 as the same index doesnt work. One of these 2 ideeas dont work ☹ … I guess that my “contor” is the issue, and need something else to retrieve index of list1`s current value

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [June 26, 2021, 3:30pm UTC](https://community.thunkable.com/t/retrieving-data-from-a-list-based-on-another-sorted-list/1365355/8 "2021-06-26T15:30:39Z")

</div>

It should be structured this way

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/e/4e7232a5d847d33c4c75914318087079dfd2bf5f.png)

---

<div class="post-metadata">

**Author:** ![mimostel](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/mimostel/32/107661_2.png) [@mimostel](https://community.thunkable.com/u/mimostel)\
**Post date:** [June 26, 2021, 7:34pm UTC](https://community.thunkable.com/t/retrieving-data-from-a-list-based-on-another-sorted-list/1365355/9 "2021-06-26T19:34:01Z")

</div>

Thank you for your time @muneer , but i still didnt get it ☹  
Trying to follow your ideea, i made a simple example:

 ![screen](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/e/7e24545d6060984970f3ccbc4600d4894866800c.png)  
expecting that on start, ill get as result B, D, A, C.  
I got instead Error 🙂  
Thats because INDEX gets value from list, and not value`s index from list

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [June 26, 2021, 8:37pm UTC](https://community.thunkable.com/t/retrieving-data-from-a-list-based-on-another-sorted-list/1365355/10 "2021-06-26T20:37:13Z")

</div>

I mean this way

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/3/b31a6bd3c622fe447d2a2bedc101c70a5c582ab4.png)

Now, every element in the list has both the number and the corresponding letter.

---

<div class="post-metadata">

**Author:** ![mimostel](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/mimostel/32/107661_2.png) [@mimostel](https://community.thunkable.com/u/mimostel)\
**Post date:** [June 26, 2021, 8:41pm UTC](https://community.thunkable.com/t/retrieving-data-from-a-list-based-on-another-sorted-list/1365355/11 "2021-06-26T20:41:26Z")

</div>

oh, got it now… need to rethink the whole variables for that. thank you.  
the problem is that i do not know the lenght of lists, so i need to generate this new object dinamically, but this will do it 🙂

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [June 26, 2021, 8:52pm UTC](https://community.thunkable.com/t/retrieving-data-from-a-list-based-on-another-sorted-list/1365355/12 "2021-06-26T20:52:13Z")

</div>

To make it clearer, I added a `List Viewer` and a `button` in the screen and following is the code in the `click` event of the button. Every time you click the list will be randomly shuffled but you can see from the list that they relation between the numbers and letters remain unchanged.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/e/9/e93a4102e505dea93f704e4c03cc474b357fe457.png)

---

<div class="post-metadata">

**Author:** ![mimostel](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/mimostel/32/107661_2.png) [@mimostel](https://community.thunkable.com/u/mimostel)\
**Post date:** [June 26, 2021, 9:36pm UTC](https://community.thunkable.com/t/retrieving-data-from-a-list-based-on-another-sorted-list/1365355/13 "2021-06-26T21:36:25Z")

</div>

“shuffle” is the easy thing… but i need it to be sorted by value1 in your examples ☹ … and dunno how to… and im returning at the beginning of the problem…

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [June 26, 2021, 9:53pm UTC](https://community.thunkable.com/t/retrieving-data-from-a-list-based-on-another-sorted-list/1365355/14 "2021-06-26T21:53:11Z")

</div>

[https://x.thunkable.com/projectPage/60d78e2a5e21e600110b78b4](https://x.thunkable.com/projectPage/60d78e2a5e21e600110b78b4)

Check this.

Remove the shuffle block and use `app variable myList` to see sorted list.

I made it just in case you ask.

---

<div class="post-metadata">

**Author:** ![mimostel](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/mimostel/32/107661_2.png) [@mimostel](https://community.thunkable.com/u/mimostel)\
**Post date:** [June 26, 2021, 10:01pm UTC](https://community.thunkable.com/t/retrieving-data-from-a-list-based-on-another-sorted-list/1365355/15 "2021-06-26T22:01:51Z")

</div>

need to study further to understand all of those… JSON …mmm …  
thank you very much for your time…

and finally got the right answer… JSON was the key and with your help i learned something new… thank you

 ![screen](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/5/25fbe8110b42abeab89798cf32fa4a36246a1934.png)

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [June 27, 2021, 7:41am UTC](https://community.thunkable.com/t/retrieving-data-from-a-list-based-on-another-sorted-list/1365355/16 "2021-06-27T07:41:22Z")

</div>

That’s nice to know.

I have also added the standard sort algorithm to the project. If you remix now you will see a sort button.

---

<div class="post-metadata">

**Author:** ![mimostel](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/mimostel/32/107661_2.png) [@mimostel](https://community.thunkable.com/u/mimostel)\
**Post date:** [June 28, 2021, 3:55pm UTC](https://community.thunkable.com/t/retrieving-data-from-a-list-based-on-another-sorted-list/1365355/17 "2021-06-28T15:55:37Z")

</div>

Hello thunkers.  
@muneer , thank you again for your solution. Works like a charm for 1 digit values, when even if numbers are treated as text, 1 will be smaller as 5 in ascending order, and so on…  
But if values are higher, app will say, for example, that 100 is smaler than 5 :)… because as text it will compare 1 to 5 first. (sorting as numbers wont help in your solution…)  
Any other ideea to workaround this new issue ? 🙂  
Thank you.

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [June 28, 2021, 5:11pm UTC](https://community.thunkable.com/t/retrieving-data-from-a-list-based-on-another-sorted-list/1365355/18 "2021-06-28T17:11:00Z")

</div>

That is very easy, in the project I shared I included a sorting function. In it I’m comparing “value1”, so if you have it as number it will compare it the correct way or you can include the `get property of value1` inside a math function to force it to change to number.

If this is not clear enough, I can change the project to reflect that later when I’m at my computer.

Happy Thunking!

**[Edit]**

This is how it starts  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/a/c/ac2cb5b2c2b91c7b88ea6c99d8af26e7edf919e2.png)

This is after sorting  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/3/b3a126c58f15096c5130f7a69bf8c4202b64ac97.png)

This is the project [link](https://x.thunkable.com/projectPage/60d78e2a5e21e600110b78b4)

---

<div class="post-metadata">

**Author:** ![mimostel](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/mimostel/32/107661_2.png) [@mimostel](https://community.thunkable.com/u/mimostel)\
**Post date:** [June 28, 2021, 8:22pm UTC](https://community.thunkable.com/t/retrieving-data-from-a-list-based-on-another-sorted-list/1365355/19 "2021-06-28T20:22:21Z")

</div>

thank you @muneer for taking so much time in this issue…  
already applied in my project your first ideea, using JSON 🙂  
im not the type that only copy paste someone else`s ideea, so i need to understand 1st what you have done with this new approach, using those functions and so on… 🤔… so many variables there that cant see it initialized and so on 🙂  
thank you again.

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [June 28, 2021, 8:56pm UTC](https://community.thunkable.com/t/retrieving-data-from-a-list-based-on-another-sorted-list/1365355/20 "2021-06-28T20:56:48Z")

</div>

I’m taking the list as input to the function and take the first element of the list and assume it is the lowest number.  
I then going into a while loop (as long as there are entries in the list)  
I then go into another loop inside the first loop going through each entry in the list and compare it with my lowest entry.  
If the entry in the list is lower than my “lowest entry” then I take the entry in the list making it my new “lowest entry”  
At the end of the inner loop my “lowest entry” is removed from the list and added to the result list and start the outer loop again.

If with every iteration of the outer loop you are removing an entry from the list and adding it to the result list then by the end of the loop (when the original list has no more entries) you will have the result list ordered.

That is all in short.

[Next page](https://community.thunkable.com/t/retrieving-data-from-a-list-based-on-another-sorted-list/1365355.md?page=2)
