import math


def kl_divergence(p,q) :
    """Return Kullback-Leibler divergence for two probability distributions
    p and q.  p and q should be indexable objects of the same length where
    p_i corresponds to q_i.
    """
    kl_sum = 0.
    for p_i, q_i in zip(p,q) :
        if p_i != 0 and q_i != 0 :
            kl_sum += p_i * math.log(p_i/q_i)
    return kl_sum