How to compare two list?

Example as
List1 = 1,2,3,4
List2 = 4,3,2,1
List3 = 1,2,3,4

List1 != List2
List1 = List3
I want to compare both num and location in list, how do I do this?

There is no built-in way to compare full lists. Youā€™d have to use a loop to check each item against the other list.

To solve your problem, you need to convert lists to strings (text) and compare strings.

ŠøŠ·Š¾Š±Ń€Š°Š¶ŠµŠ½ŠøŠµ

Best regards, Alex
ACtech demo project
Thunkable X Basic Programming Course
Block Reference
Component Reference
Bug tracker
Polipaint
Map canvas
Method Inspector
Performance

1 Like

@actech Smart! Is there a length limit to strings in Thunkable? I could see that conversion working for a list with small values (1 to 4) but Iā€™m wondering about something that uses longer numbers (1000 to 4000).

I work with lists that consist of several tens of thousands of records and without any problems convert them to strings and vice versa.

1 Like

Hereā€™s a demo of what @actech described: https://x.thunkable.com/copy/c13472b100564cdf35d3d5a4c28326ff

Do this:

image

with this, the result of ā€œcompare_lists(List1,List2)ā€ would be ā€˜falseā€™, while ā€œcompare_lists(List1,List3)ā€ would return ā€˜trueā€™.

The strength of this approach is that lists of different length are immediately reported as not being the same, and that the comparison of elements stops as soon as there is one mismatch. Only in the case of identical lists would all the elements be checked one against one.

3 Likes

Thanks