List logic to combine and filter lists


I want to combine items from matching list indices to sub lists as shown in the middle code block and later make sub lists again if they include a common item ( list 0 is combined with list 2 as “a” is common to both).
Is it possible to do this?


It is possible.


Thanks @Tomasz. Some great logic you got there.