def match(A, B, equivalence = lambda a,b: a is b):
    """
    Returns all elements of A that are exactly the same as an element of B. ie. a is b for some b in B.
    You can change the equivalence relation used.
    """
    matches = []
    for a in A:
        for b in B:
            if equivalence(a, b):
                matches.append(a)
                break
    return matches