def score(x, y, w):
    """
    Calcutates directional distributional similarity http://dl.acm.org/citation.cfm?id=1897650
    >>> score([1, 2], [1, 3], {1:1.5, 2:1.0, 3:1.0})
    0.42857142857142855
    """
xx = set(x)
yy = set(y)
return 1.0 * sum(i * w[i] for i in xx & yy) / sum(i * w[i] for i in x)
Синтаксис математической формулы в Python