def is_tree(G):
 if (len(G) == 0):
  raise nx.exception.NetworkXPointlessConcept('G has no nodes.')
 if G.is_directed():
  is_connected = nx.is_weakly_connected
 else:
  is_connected = nx.is_connected
 return (((len(G) - 1) == G.number_of_edges()) and is_connected(G))

def is_tree ( G ) : if ( len ( G ) == 0 ) : raise nx . exception . NetworkXPointlessConcept ( 'G has no nodes.' ) if G . is_directed ( ) : is_connected = nx . is_weakly_connected else : is_connected = nx . is_connected return ( ( ( len ( G ) - 1 ) == G . number_of_edges ( ) ) and is_connected ( G ) )
returns true if g is a tree .