I have a list of tuples like this :
all_tuples=[(92, 242),(355, 403),(355, 436),(355, 489),(403, 436),(436, 489),(515, 517),(517, 859),(634, 775),(701, 859),(775, 859)]
and I need to take the intersection of all tuples and union them.
The desired result = [{92, 242},{355, 403,436,489},{515, 517,859,701,775,634}]
That is the intersected tuples are union iteratively.
I tried to convert the tuples to sets and then take the intersection but did not work. Any idea?
This is network problem , using networkx
import networkx as nx
G=nx.Graph()
all_tuples=[(92, 242),(355, 403),(355, 436),(355, 489),(403, 436),(436, 489),(515, 517),(517, 859),(634, 775),(701, 859),(775, 859)]
G.add_edges_from(all_tuples)
list(nx.connected_components(G))
Out[1216]: [{92, 242}, {355, 403, 436, 489}, {515, 517, 634, 701, 775, 859}]
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments