Sort/Group List by string values

Hi Forum

I am looking to sort/group the list in the GetItemAtIndex list into a sublist by the UniqueItems list - please see attached.

I am hoping to get the following solution:

0
LT-CM-1
LT-CM-2
1
FN-CSB-1
FN-CSB-2
2
SW-BN-1
SW-BN-2

I have tried string.Contains but cannot get my head around the logic to achieve this.
Any help would be greatly appreciated.
Many thanks

If your index is always 1 item long you can do something like this:

Hi Jonathan

Many thanks for this! I was looking at the GroupByKey. Sadly the last value will increase to 2 or more. Any thoughts?

Thank you very much again.

Regards
Tim

Sorry, 2 or more digits at the end I mean.

Hi Jonathan

Using your approach I think I have got it. See attached, using the string length and GroupByKey seems to have done it.

Many thanks again for your help.
Tim

Perhaps this helps?

Hi 3Pinter

This works a treat! Thank you so much. Just followed it below.

Thank you again for everyone’s help.

Cheers
Tim

It doesn’t need to be so complicated, the first letters in your key are unique enough…

Home.dyn (7.8 KB)

1 Like

Hi erfajo

This is brilliant, very nice, thank you.

Thank you for the excellent solutions.
Cheers
Tim

If it should be really effecient… then do it with python :slight_smile:

If you have the keys (as in your case), then it is really easy…
Home.dyn (6.9 KB)

t1 = []
for s1 in IN[0]:
    t2= []
    for s2 in IN[1]:
        if s1 in s2:
    		t2.append(s2)
    t1.append(t2)
OUT = t1
2 Likes

Thanks again erfajo. This looks great - wish I was at Python level, but still at OOTB!

Thanks again
Tim