I am trying to combine 2 different lists of lists based on common elements between them if present
Say,
list1 = [['a1', 'a2', 'b2'], ['h1', 'h2'], ['c1', 'd5']]
list2 = [['b5', 'a2'], ['d1', 'd2', 'c1', 'd3']]
I need a resultant list such that, for common element id "a2" or "c1". from both list, we get
combinedList = [['a1', 'a2', 'b2', 'b5'], ['d1', 'd2', 'c1', 'd3', 'd5'], ['h1', 'h2']]
Tried and Failed:
I have tried using NetworkX Graph to pass lists, but in vain as they contain different lengths. Also tried to sort the list of list and tried grouping based on first element and that too didn't work.