How to parse a list and retrieve items the contain a specific property?

@muneer @tatiang

Hi, I hope you are doing well.

I have quite a complex logic problem in my app that is seriously stumping me. Essentially, I would like to design an algorithm which parses a list and retrieves a list item that contains a specific property eg. a word.

This is for my school planner application. I have an ‘homework assignments’ screen in which users can enter assignments. Additionally, I have a timetable screen which displays lessons that the student has for that particular day. What I would like to happen is when the user clicks a text item on the timetable, the app displays the tasks associated with that lesson.

Currently I am storing the homework assignments in a list like so:

My timetable screen looks like this:

So essentially, I want it so that that when the user clicks say ‘computer science’, they list viewer displays all the computer science tasks. So how could I design an algorithm which parses the assignments list and retrieves all the items that contain the words ‘computer science’ and then display them on the list viewer?

I am sorry if I have not explained this very clearly. Please feel free to ask for any clarification and I will try my best to explain. Any help would be greatly appreciated. Here is the link to the project:

https://x.thunkable.com/copy/a2796de8f4238c4af5a107ee63879a82

Thanks!

1 Like

I’m sorry to say I could not find the link in your app between the subjects and the assignments.

Can you clarify this please?

There is no link at the moment, I am pretty stuck about what to do.

1 Like

A quick and dirty way to “make” a link is to have another list side by side to the Assignments list which stores the index of the selected item in Timetable in the same position of the Assignments list.

Example:
If a user selected “Computer Science”, you will store the index of this block
image

When the user enters the information of the Assignment you will insert an entry in the Assignments list and in the same time insert the saved index into the subject-assignment-reference list.

This way, you can show the assignments related to any subject.

1 Like

@muneer
Sorry I am not sure I understand what you are saying, is it possible to show some blocks on how I can do this? Thanks!

1 Like

Check this quick demo
https://x.thunkable.com/projectPage/61669e6b16c2820011182531

Of course this does not save info in database but it will demonstrate how to link a subject to an assignment. You will need the other pieces of code of saving this extra list along with the assignment list to be always in synch.

This is the version of code that I would prefer to do.
https://x.thunkable.com/projectPage/6166a603d643930011656e15
This is using objects instead of synched lists.

1 Like

@muneer

I understand what you are suggestion however, I am not sure how it would work for my case. Currently the user enters the their lessons for the timetable which is then added to a big timetable list. Therefore, how could a list be created with just the lessons as your code has done?

1 Like

When the user selects the lesson to add assignment to it then you grab the lesson name and save at instead of the index. Check for the lesson name instead of the lesson order number.

1 Like

@muneer

But my timetable is on a different screen, so say if you pick computer science, how would you search through the subjects list to find the assignments related to that subject. Right now it seems like you have suggested one integrated system but my application has two separate systems that need to be linked.

@muneer

This is my assignments screen:

1 Like

First of all you will have an app variable which means it is accessible from anywhere in the app and not limited to a screen.

image

Whenever one selects a subject, you will save this subject to the app variable, in my case, selectedSubject and then navigate to the Assignment screen.

If you use a list of objects as I demonstrated in the second example then every entry in the list of assignment has to values (the assignment info, and the subject it relates to)

This way you use the function I have in the example to view only the assignment related to the subject.

1 Like

@muneer

I think I understand your solution, but I am not sure how to integrate it into my application. Could you show me how you would do it please?

https://x.thunkable.com/copy/de545da0b04b9d017efec514b03c538dhttps://x.thunkable.com/copy/de545da0b04b9d017efec514b03c538d

1 Like

I tried to open the link many times but I keep getting empty page. Will try later, maybe it’s an internet issue or design server busy.

Just tried again after 3 hours but still the link does not work.

1 Like

@muneer

Try this link:

https://x.thunkable.com/copy/6beff67002a2ea2fbe0cede595a75d9c

I have since tried to add a code which will see if the selected subject is contained in the assignment, however, it is not working at the moment.

You’re setting the list viewer’s text items to a single value within your loop. Instead, you need to add that single value to a list and then once the loop has completed, set the list viewer’s text items to that list.

I’m not in front of a computer but if that doesn’t make sense, I can post a screenshot of the blocks later.

@tatiang

Like this? I still is not working though.

1 Like

Almost! The in list get # block requires an actual number, an integer. But you’re giving it j which is a list item. So you end up telling Thunkable to see if list item # “Write an algorithm” contains “Computer Science” instead of what you actually want. You either have to use a count from 1 to x by 1 loop block or… what I would do here is to replace the in list get # block with just the j block. So it will say does j contain app variable selected subject.

By the way, it’s a very minor point but the = true block is optional here because the does contain block returns true or false. It’s also fine to just check if [does contain...] and leave off the = block.

1 Like

Like this:

1 Like

The code is working however, there is a slight problem with the condition that checks if j is contained in ‘selected subject’. When the ‘timetable’ list was populated, each lesson was saved with its corresponding lesson number eg. Period 3: computer science. Therefore, even if the selected subject is computer science, it will return false as there is a ‘Period 3’ substring in front of it.

I think this will require the ‘get substring’ block however, I am not sure how to implement it. Thank you so much for your help!

1 Like

Never mind, I got it to work:

2 Likes