def getAvgPrecision(args):
    """Get average precision

    Similar notice here as in getRL
    """
    usr2NonzeroCols = args['usr2NonzeroCols']
    u2predictions = args['u2predictions']
    colNums = len(next(usr2NonzeroCols.itervalues()))
    prec = 0.0
    for usrid in u2predictions:
        y_nonzeroCols = usr2NonzeroCols[usrid]
        bestCols = u2predictions[usrid]
        col2AllRank = {}
        score = 0.0
        for cnt in range(0, colNums):
            ind = colNums - 1 - cnt
            if y_nonzeroCols[ind] == bestCols[ind]:
                col2AllRank[y_nonzeroCols[ind]] = ind + 1
            else:
                col = y_nonzeroCols[ind]
                col2AllRank[col] = col + len(filter(lambda v: v > col,
                    bestCols)) + 1
        rankedList = sorted(col2AllRank.items(), key=lambda x: x[1])
        for ind, val in enumerate(rankedList):
            score += float(ind + 1) / val[1]
        prec += score / colNums
    return prec / len(u2predictions)
