0

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.

MaxB
  • 428
  • 1
  • 8
  • 24
  • 1
    Why would A lead to AB,BC and CD? Is it because they are consecutive? What would be the group returned for B? – Jkind9 Jun 19 '19 at 14:50
  • 1
    You need the networkx module: `import networkx as nx` – MEdwin Jun 19 '19 at 14:51
  • @Jkind9 Anything 'related' to A would be part of the group. The group returned for B, C, and D would be the exact same. My thinking is to drop the elements in the group from the original list so that I don't attempt to group the same thing a second time – MaxB Jun 19 '19 at 14:53
  • 1
    Your own question :-) – BENY Jun 19 '19 at 14:53
  • @WeNYoBen I don't think it is a duplicate because that question drops data and moves it around, here I am trying to build groupings regardless of start point. – MaxB Jun 19 '19 at 14:54

0 Answers0