def get_eulerian_tour():
 global graph
 tour = get_a_tour()
 if graph:
  loop = enumerate(tour[:(-1)])
  l = loop.__next__()
  i = l[0]
  node = l[1]
  try:
   while True:
    if ((node in list(zip(*graph))[0]) or (node in list(zip(*graph))[1])):
     t = get_a_tour()
     j = t.index(node)
     tour = (((tour[:i] + t[j:(-1)]) + t[:(j + 1)]) + tour[(i + 1):])
     if (not graph):
      return tour
     loop = enumerate(tour[:(-1)])
    l = loop.__next__()
    i = l[0]
    node = l[1]
  except StopIteration:
   print "Your graph doesn't seem to be connected"
   exit()
 else:
  return tour

def get_eulerian_tour ( ) : global graph tour = get_a_tour ( ) if graph : loop = enumerate ( tour [ : ( - 1 ) ] ) l = loop . __next__ ( ) i = l [ 0 ] node = l [ 1 ] try : while True : if ( ( node in list ( zip ( * graph ) ) [ 0 ] ) or ( node in list ( zip ( * graph ) ) [ 1 ] ) ) : t = get_a_tour ( ) j = t . index ( node ) tour = ( ( ( tour [ : i ] + t [ j : ( - 1 ) ] ) + t [ : ( j + 1 ) ] ) + tour [ ( i + 1 ) : ] ) if ( not graph ) : return tour loop = enumerate ( tour [ : ( - 1 ) ] ) l = loop . __next__ ( ) i = l [ 0 ] node = l [ 1 ] except StopIteration : print "Your graph doesn't seem to be connected" exit ( ) else : return tour
this function returns a eulerian tour for the input graph .