(self, format="newick")
Formats the dendrogram in a foreign format.

        Currently only the Newick format is supported.

        Example:

            >>> d = Dendrogram([(2, 3), (0, 1), (4, 5)])
            >>> d.format()
            '((2,3)4,(0,1)5)6;'
            >>> d.names = list("ABCDEFG")
            >>> d.format()
            '((C,D)E,(A,B)F)G;'
Formats the dendrogram in a foreign format.
Formats the dendrogram in a foreign format .
def format(self, format="newick"):
        """Formats the dendrogram in a foreign format.

        Currently only the Newick format is supported.

        Example:

            >>> d = Dendrogram([(2, 3), (0, 1), (4, 5)])
            >>> d.format()
            '((2,3)4,(0,1)5)6;'
            >>> d.names = list("ABCDEFG")
            >>> d.format()
            '((C,D)E,(A,B)F)G;'
        """
        if format == "newick":
            n = self._nitems + self._nmerges
            if self._names is None:
                nodes = list(range(n))
            else:
                nodes = list(self._names)
            if len(nodes) < n:
                nodes.extend("" for _ in range(n - len(nodes)))
            for k, (i, j) in enumerate(self._merges, self._nitems):
                nodes[k] = "(%s,%s)%s" % (nodes[i], nodes[j], nodes[k])
                nodes[i] = nodes[j] = None
            return nodes[-1] + ";"
        raise ValueError("unsupported format: %r" % format)
def format ( self , format = "newick" ) : if format == "newick" : n = self . _nitems + self . _nmerges if self . _names is None : nodes = list ( range ( n ) ) else : nodes = list ( self . _names ) if len ( nodes ) < n : nodes . extend ( "" for _ in range ( n - len ( nodes ) ) ) for k , ( i , j ) in enumerate ( self . _merges , self . _nitems ) : nodes [ k ] = "(%s,%s)%s" % ( nodes [ i ] , nodes [ j ] , nodes [ k ] ) nodes [ i ] = nodes [ j ] = None return nodes [ - 1 ] + ";" raise ValueError ( "unsupported format: %r" % format )