def isUndirected(G):
 for v in G:
  if (v in G[v]):
   return False
  for w in G[v]:
   if (v not in G[w]):
    return False
 return True

def isUndirected ( G ) : for v in G : if ( v in G [ v ] ) : return False for w in G [ v ] : if ( v not in G [ w ] ) : return False return True
check that g represents a simple undirected graph .