I have a list with several elements.
For example, if an element has "apple" in the text, then the element should be added to the category "fruit". This allows you to have several categories in a list viewer.
Like a shopping list that is sorted by categories such as "vegetables", "meat", "fruit" and so on
If I understood you correctly, you have a list of elements (apple, broccoli, chicken, orange, beetroot, carrot) and another list of their categories (fruit, vege, meat, fruit, vege, vege)
No w you want to sort them as per category, by fruit then result will be (apple, orange); by vege (broccoli, beetroot, carrot)
Like this?