def recallAtK(cls, ranking, k):
    """
    This function takes a class label ('cls'), a ranked list 'ranking' of (class,score)
    pairs (ranked by virtue of being sorted in descending order of score) and
    a parameter 'k', and returns 1 if 'cls' is in 'ranking' in the top 'k' ranked
    classes.  The word 'recall' is for conformity with IR terminology.  Think of this
    as an indicator function saying whether 'cls' is "recalled" in the top 'k' classes
    of 'ranking'.

    @param cls: [the string name of the class to search for in the top k ranked classes in
    'ranking'.]
    @param ranking: [the ranked list of (class,score) pairs.]
    @param k: [the number of top ranked classes to search in for 'cls'.]
    @return: [1 if 'cls' is in the top 'k' slots of 'ranking' and 0 otherwise.]

    >>> ranking = [('a',1.5), ('b',0.45), ('c',0.22), ('d',0.1)]
    >>> recallAtK('c',ranking,1)
    0
    >>> recallAtK('c',ranking,2)
    0
    >>> recallAtK('c',ranking,3)
    1
    >>> recallAtK('c',ranking,4)
    1
    >>> recallAtK('a',ranking,1)
    1
    >>> recallAtK('a',ranking,4)
    1
    """
    indicator = 0
    rank = 0
    for (cl,score) in ranking:
        rank += 1
        if rank <= k:
            if (cl == cls):
                indicator = 1
                break
        else:
            break
    return indicator