def idf(self, term, transform=None):
docs_with_term = <NUM_LIT:0><EOL>docs = self.docs_of_words()<EOL>for doc in docs:<EOL><INDENT>doc_set = set(doc)<EOL>if transform:<EOL><INDENT>transformed_doc = []<EOL>for word in doc_set:<EOL><INDENT>transformed_doc.append(transform(word))<EOL><DEDENT>doc_set = set(transformed_doc)<EOL><DEDENT>if term in doc_set:<EOL><INDENT>docs_with_term += <NUM_LIT:1><EOL><DEDENT><DEDENT>if docs_with_term == <NUM_LIT:0>:<EOL><INDENT>return float('<STR_LIT>')<EOL><DEDENT>return log10(len(docs) / docs_with_term)<EOL>
r"""Calculate the Inverse Document Frequency of a term in the corpus.

        Parameters
        ----------
        term : str
            The term to calculate the IDF of
        transform : function
            A function to apply to each document term before checking for the
            presence of term

        Returns
        -------
        float
            The IDF

        Examples
        --------
        >>> tqbf = 'The quick brown fox jumped over the lazy dog.\n\n'
        >>> tqbf += 'And then it slept.\n\n And the dog ran off.'
        >>> corp = Corpus(tqbf)
        >>> print(corp.docs())
        [[['The', 'quick', 'brown', 'fox', 'jumped', 'over', 'the', 'lazy',
        'dog.']],
        [['And', 'then', 'it', 'slept.']],
        [['And', 'the', 'dog', 'ran', 'off.']]]
        >>> round(corp.idf('dog'), 10)
        0.4771212547
        >>> round(corp.idf('the'), 10)
        0.1760912591