Find common values in python list in ordered format

Hello All,
There are various codes available to find the intersection between two sets in python. But my case is the following:

I want to find the continual common pattern in different lists compared to list1.
(i have underlined the longest common patterns in set a and set b)

a = [1, 2, 3, 5, 8, 9, 4, 9]
b= [1, 3, 2, 3, 9, 4, 9, 5, 9]
common_ordered = [i for in a if i in b]
print common_ordered

The output I get is:

[1, 2, 3, 5, 9, 4, 9]

but my expected output is:

[(2 , 3) , (9, 4, 9)]

Any suggestions would help

I do not know if odict common_ordered works the way you want on an unordered list or dict.

common_ordered expects elements to be in order as far as I know. Your elements are not ordered.

Try this for a sample - switch the example code from C to python by clicking the python button.

Printing Longest Common Subsequence - GeeksforGeeks