# Revision history [back]

The following deletes one arc from each of the cycles of length 2. If you are interested in preserving any particular arc you should adapt this to suit your needs.

LG.delete_edges( [ ((x,y,None),(y,x,None)) for x,y in G.edges(labels=False) ] )


The following deletes one arc from each of the line graph you obtain contains cycles of length 2. 2 because the digraph that to_directed() returns contains arcs (x,y) and (x,y) for each edge xy in the original graph.

If you are interested want to avoid these kind of cycles in preserving any particular arc the line graph you should adapt just need to get an arbitrary orientation of the original graph. You can achieve this to suit your needs.with

LG.delete_edges( [ ((x,y,None),(y,x,None)) D=DiGraph()
for x,y in G.edges(labels=False) ] )
graphs.CompleteGraph(4).edges(labels=None):
if random()>= 0.5:
else:


The line graph you obtain contains cycles of length 2 because the digraph D that to_directed() returns contains arcs (x,y) and (x,y) for each edge xy in the original graph.graph G.

If From what you show in your diagram you want to avoid these kind of cycles in the line graph you just need to get an arbitrary orientation of of D minus all the original graph. You can achieve arcs connecting vertices that came from the same edge in G. Maybe this withwill do the job

D=DiGraph()
G=graphs.CompleteGraph(4)
D=G.to_directed()
L=D.line_graph()
L.delete_edges([((x,y,None), (y,x,None)) for x,y in graphs.CompleteGraph(4).edges(labels=None):
if random()>= 0.5: