Next / Previous / Contents / Shipman's homepage

7.4. Taxon.__cmp__(): Compare taxa in phylogenetic order

This method is called when the usual Python cmp() function is applied to two Taxon objects. It orders them using the phylogenetic key.

txny.py
# - - -   T a x o n . _ _ c m p _ _   - - -

    def __cmp__ ( self, other ):
        """Compare two taxa, order them phylogenetically.

          [ self and other are Taxon objects ->
              if self occurs before other in phylogenetic order ->
                return -1
              else if self is the same taxon as other ->
                return 0
              else -> return 1 ]
        """
        return cmp ( self.txKey, other.txKey )