Finding a list in another list

Let’s say I have a list a which is [1,2,9,5,4,3,6] and another list b which is [5,4]. I want to find the first (or last, doesn’t matter) instance of list b in list a here it would be 4 because the elements 4 and 5 of list a are the same as elements 1 and 2 of list b.

I tried making this MONSTER of a function and I think it would work but desmos doesn’t support lists inside of other lists.


here is the “code” for it: f_{inditeminlist}\left(i_{temtofind},l_{isttosearchin}\right)=-\operatorname{sort}\left(-\left[\left{\left[l_{isttosearchin}\left[i+k\right]\operatorname{for}k=\left[0…i_{temtofind}.\operatorname{length}-1\right]\right]=i_{temtofind}:i,0\right}\right]\right)\left[1\right]

For anyone wondering what I’m using this for, I am making a programming language in desmos, and I need that to find the position of the definition of a custom function.

If you can help, please do! :slight_smile:

I came up with this, though there may be a prettier way to do it! find a sublist in a list | Desmos

So, funny thing, 32 minutes after this reply I figured out by myself a function that works.
Here’s the thing you can copy and paste:
f_{inditeminlist}\left(i_{temtofind},l_{isttosearchin}\right)=\left[\left{\prod_{n=1}^{i_{temtofind}.\operatorname{length}}\left[\left{l_{isttosearchin}\left[i+k\right]=i_{temtofind}\left[k+1\right]:1,0\right}\operatorname{for}k=\left[0…i_{temtofind}.\operatorname{length}-1\right]\right]\left[n\right]=1:i,0\right}\operatorname{for}i=\left[1…l_{isttosearchin}.\operatorname{length}\right]\right]
Overall I think my function is a tad less messy, but yours is pretty good too, so congrats on that! :slight_smile:

Great! Do you mind linking it in a graph? I can’t get that to paste properly.

Sure! Here is the link: Finding a list in another list | Desmos

Sorry to revive this, but would there be a way to do that without matching for order? Like I would input a main list and a list of numbers, and it would spit out the positions of each number in the list?

Something like this? find indices of sublist in list | Desmos

I’m assuming that you are looking for the first instance of each sublist element in the main list?

That’s exactly what I was looking for, thank you!