(tree, n)
return L
Return the Prufer sequence for a tree given as a list of edges where
        ``n`` is the number of nodes in the tree.

        Examples
        ========

        >>> from sympy.combinatorics.prufer import Prufer
        >>> a = Prufer([[0, 1], [0, 2], [0, 3]])
        >>> a.prufer_repr
        [0, 0]
        >>> Prufer.to_prufer([[0, 1], [0, 2], [0, 3]], 4)
        [0, 0]

        See Also
        ========
        prufer_repr: returns Prufer sequence of a Prufer object.
Return the Prufer sequence for a tree given as a list of edges where
        ``n`` is the number of nodes in the tree.
Return the Prufer sequence for a tree given as a list of edges where n is the number of nodes in the tree .
def to_prufer(tree, n):
        """Return the Prufer sequence for a tree given as a list of edges where
        ``n`` is the number of nodes in the tree.

        Examples
        ========

        >>> from sympy.combinatorics.prufer import Prufer
        >>> a = Prufer([[0, 1], [0, 2], [0, 3]])
        >>> a.prufer_repr
        [0, 0]
        >>> Prufer.to_prufer([[0, 1], [0, 2], [0, 3]], 4)
        [0, 0]

        See Also
        ========
        prufer_repr: returns Prufer sequence of a Prufer object.

        """
        d = defaultdict(int)
        L = []
        for edge in tree:
            # Increment the value of the corresponding
            # node in the degree list as we encounter an
            # edge involving it.
            d[edge[0]] += 1
            d[edge[1]] += 1
        for i in xrange(n - 2):
            # find the smallest leaf
            for x in xrange(n):
                if d[x] == 1:
                    break
            # find the node it was connected to
            y = None
            for edge in tree:
                if x == edge[0]:
                    y = edge[1]
                elif x == edge[1]:
                    y = edge[0]
                if y is not None:
                    break
            # record and update
            L.append(y)
            for j in (x, y):
                d[j] -= 1
                if not d[j]:
                    d.pop(j)
            tree.remove(edge)
        return L
def to_prufer ( tree , n ) : d = defaultdict ( int ) L = [ ] for edge in tree : # Increment the value of the corresponding # node in the degree list as we encounter an # edge involving it. d [ edge [ 0 ] ] += 1 d [ edge [ 1 ] ] += 1 for i in xrange ( n - 2 ) : # find the smallest leaf for x in xrange ( n ) : if d [ x ] == 1 : break # find the node it was connected to y = None for edge in tree : if x == edge [ 0 ] : y = edge [ 1 ] elif x == edge [ 1 ] : y = edge [ 0 ] if y is not None : break # record and update L . append ( y ) for j in ( x , y ) : d [ j ] -= 1 if not d [ j ] : d . pop ( j ) tree . remove ( edge ) return L