@not_implemented_for('directed')
def to_nested_tuple(T, root, canonical_form=False):
 def _make_tuple(T, root, _parent):
  'Recursively compute the nested tuple representation of the\n        given rooted tree.\n\n        ``_parent`` is the parent node of ``root`` in the supertree in\n        which ``T`` is a subtree, or ``None`` if ``root`` is the root of\n        the supertree. This argument is used to determine which\n        neighbors of ``root`` are children and which is the parent.\n\n        '
  children = (set(T[root]) - {_parent})
  if (len(children) == 0):
   return ()
  nested = (_make_tuple(T, v, root) for v in children)
  if canonical_form:
   nested = sorted(nested)
  return tuple(nested)
 if (not nx.is_tree(T)):
  raise nx.NotATree('provided graph is not a tree')
 if (root not in T):
  raise nx.NodeNotFound('Graph {} contains no node {}'.format(T, root))
 return _make_tuple(T, root, None)

@ not_implemented_for ( 'directed' ) def to_nested_tuple ( T , root , canonical_form = False ) : def _make_tuple ( T , root , _parent ) : children = ( set ( T [ root ] ) - { _parent } ) if ( len ( children ) == 0 ) : return ( ) nested = ( _make_tuple ( T , v , root ) for v in children ) if canonical_form : nested = sorted ( nested ) return tuple ( nested ) if ( not nx . is_tree ( T ) ) : raise nx . NotATree ( 'provided graph is not a tree' ) if ( root not in T ) : raise nx . NodeNotFound ( 'Graph {} contains no node {}' . format ( T , root ) ) return _make_tuple ( T , root , None )
returns a nested tuple representation of the given tree .