Getting the longest link in list of links in python

Viewed 64

I have a list of edges as follows:

edges_1 = ['a::b::c', 'a::b', 'a', 'a::d','a::d::e', 'a::d::e::f']
edges_2 = ['a', 'b', 'c']

I am trying to write a function which return the longest links.. which for above cases will return

['a::b::c','a::d::e::f']

and for second case

['a', 'b', 'c']

My thoughts is using networkx and build a graph and then traverse the longest sequence.. but i was wondering if there is another data structure or approach I am missing which would solve this case.

2 Answers
Related