def initial_nodes_to_merge(tree):
 to_process = set([])
 for n in tree.tips():
  sibs_are_tips = [s.istip() for s in n.siblings()]
  if all(sibs_are_tips):
   to_process.add(n.Parent)
 return to_process

def initial_nodes_to_merge ( tree ) : to_process = set ( [ ] ) for n in tree . tips ( ) : sibs_are_tips = [ s . istip ( ) for s in n . siblings ( ) ] if all ( sibs_are_tips ) : to_process . add ( n . Parent ) return to_process
determine what nodes are safe to process first the first nodes to process are those internal nodes that have tips as children .