def _order_cluster_tree(Z):
 q = deque()
 tree = to_tree(Z)
 q.append(tree)
 nodes = []
 while q:
  node = q.popleft()
  if (not node.is_leaf()):
   bisect.insort_left(nodes, node)
   q.append(node.get_right())
   q.append(node.get_left())
 return nodes

def _order_cluster_tree ( Z ) : q = deque ( ) tree = to_tree ( Z ) q . append ( tree ) nodes = [ ] while q : node = q . popleft ( ) if ( not node . is_leaf ( ) ) : bisect . insort_left ( nodes , node ) q . append ( node . get_right ( ) ) q . append ( node . get_left ( ) ) return nodes
returns clustering nodes in bottom-up order by distance .