class_docstr: The Prufer correspondence is an algorithm that describes the
  bijection between labeled trees and the Prufer code. A Prufer
  code of a labeled tree is unique up to isomorphism and has
  a length of n - 2.
  
  Prufer sequences were first used by Heinz Prufer to give a
  proof of Cayley's formula.
  
  References
  ==========
  
  .. [1] https://mathworld.wolfram.com/LabeledTree.html
class_docstr_tok: ["The","Prufer","correspondence","is","an","algorithm","that","describes","the","bijection","between","labeled","trees","and","the","Prufer","code",".","A","Prufer","code","of","a","labeled","tree","is","unique","up","to","isomorphism","and","has","a","length","of","n","-","2",".","Prufer","sequences","were","first","used","by","Heinz","Prufer","to","give","a","proof","of","Cayley","'s","formula",".","References","==========","..","[","1","]","https",":","\/\/mathworld.wolfram.com\/LabeledTree.html"]
docstr: 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.
docstr_tok: ["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","."]
code: 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 range(n - 2):
          # find the smallest leaf
          for x in range(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
  
imports: from sympy.core import Basic
  from sympy.core.containers import Tuple
  from sympy.tensor.array import Array
  from sympy.core.sympify import _sympify
  from sympy.utilities.iterables import flatten, iterable
  from sympy.utilities.misc import as_int
  from collections import defaultdict
label_desc: Use image node_id 6 for calling the Prufer obj's underlying member method code with example usage: obj.to_prufer(tree, n) and returns: L