I wish to compare lists and output the similar matches that following each other in the same order.
list1 = ['a','b', 'b', 'c']
list2 = ['b', 'a', 'a', 'c']
# With the intersection() command, the output is the matching strings regardless of the order of the strings:
set(list1).intersection(set(list2))
{'a', 'b', 'c'}
# I wish to output only the strings that are following each other in the two lists. Here the two answers could be :
{'a', 'c'}
# or
{'b', 'c'}
Would you know any tricks to do it?