I have a list of lists, where each list contains some amount of words. Each list does not have to be the same length as every other list. Basically:
wordlist = [ ['cat', 'sheep', 'dog', 'pig', 'tomato'], ['apple', 'orange', 'sheep', 'dog' 'tomato'], ['cat', 'apple', 'sheep', 'tomato', 'dog'], ['garlic', 'tomato', 'dog' ]
I also have created a list of common words which can be found across all lists, for the above example, it would be:
common = ['sheep','dog', 'tomato']
I would like to now check, that for one list, if the common word appears in some order, in which other lists do those words show up in the same order. For example, in list1 the common words appear in the order ['sheep', 'dog'], and the same order appears in list2, so I should return:
list1: list2
In list3 ['tomato', 'dog'] appears in sequence, and it also does in list4, so these two get mapped. Making the total output as the following:
list1: list2
list2: list1
list3: list4
list4: list3
If list1 has common sublists in sequence with other lists, it would print as list1: list2, list5, list7 and so on. It should work for all sublists.
Is there a way of doing this?