def eulerian_circuit(G, source=None):
 if (not is_eulerian(G)):
  raise nx.NetworkXError('G is not Eulerian.')
 g = G.__class__(G)
 if (source is None):
  v = arbitrary_element(g)
 else:
  v = source
 if g.is_directed():
  degree = g.in_degree
  edges = g.in_edges
  get_vertex = itemgetter(0)
 else:
  degree = g.degree
  edges = g.edges
  get_vertex = itemgetter(1)
 vertex_stack = [v]
 last_vertex = None
 while vertex_stack:
  current_vertex = vertex_stack[(-1)]
  if (degree(current_vertex) == 0):
   if (last_vertex is not None):
    (yield (last_vertex, current_vertex))
   last_vertex = current_vertex
   vertex_stack.pop()
  else:
   arbitrary_edge = next(edges(current_vertex))
   vertex_stack.append(get_vertex(arbitrary_edge))
   g.remove_edge(*arbitrary_edge)

def eulerian_circuit ( G , source = None ) : if ( not is_eulerian ( G ) ) : raise nx . NetworkXError ( 'G is not Eulerian.' ) g = G . __class__ ( G ) if ( source is None ) : v = arbitrary_element ( g ) else : v = source if g . is_directed ( ) : degree = g . in_degree edges = g . in_edges get_vertex = itemgetter ( 0 ) else : degree = g . degree edges = g . edges get_vertex = itemgetter ( 1 ) vertex_stack = [ v ] last_vertex = None while vertex_stack : current_vertex = vertex_stack [ ( - 1 ) ] if ( degree ( current_vertex ) == 0 ) : if ( last_vertex is not None ) : ( yield ( last_vertex , current_vertex ) ) last_vertex = current_vertex vertex_stack . pop ( ) else : arbitrary_edge = next ( edges ( current_vertex ) ) vertex_stack . append ( get_vertex ( arbitrary_edge ) ) g . remove_edge ( * arbitrary_edge )
returns an iterator over the edges of an eulerian circuit in g .