I have a list:
L = ['A', 'B', 'C', 'D', 'L', 'M', 'N', 'O']
I also have a dataframe
To From
A B
B C
D C
L M
M N
N O
I am trying to perform a 'search and group' for each element of the list. For example, if we performed a search on the first element of the list, 'A', the following group would be returned.
To From
A B
B C
D C
My thinking is to implement a search tree, but haven't been able to come up with anything close.