import math


def compute_idfs(documents):
    """
    Given a dictionary of `documents` that maps names of documents to a list
    of words, return a dictionary that maps words to their IDF values.

    Any word that appears in at least one of the documents should be in the
    resulting dictionary.
    """
    idfs = dict()

    # Get unique vocabulary
    unique = []
    for vocab in documents.values():
        unique.extend(set(vocab))
    unique = set(unique)

    # calculate idf's'
    num_docs = len(documents)
    for word in unique:
        doc_count = 0
        for vocab in documents.values():
            if word in vocab:
                doc_count += 1
        idfs[word] = math.log(num_docs / doc_count)

    return idfs