def mean_ppmi_score(pdict, wlist1, wlist2):
    """ Calculate mean positive PMI over all word pairs in two word lists,
        given pre-computed PMI dictionary

        - Any negative PMI is truncated to zero
        - If there is no PMI defined for any of the word pairs,
          return -inf
    """
    total_ppmi = None
    for word1 in wlist1:
        for word2 in wlist2:
            # Enforce alphabetical order in pair
            pair = tuple(sorted([word1, word2]))
            wi, wj = pair
            if wi in pdict and wj in pdict[wi]:
                if total_ppmi is None:
                    total_ppmi = 0
                # Any negative PMIs are considered to be 0
                if pdict[wi][wj] > 0:
                    total_ppmi += pdict[wi][wj]
    if total_ppmi is not None:
        return total_ppmi / (len(wlist1)*len(wlist2))
    else:
        return float("-inf")