<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def set_elem(elem_ref, elem):
 """ Sets element referenced by the elem_ref. Returns the elem. :param elem_ref: :param elem: :return: """

    if elem_ref is None or elem_ref == elem or not is_elem_ref(elem_ref):
        return elem

    elif elem_ref[0] == ElemRefObj:
        setattr(elem_ref[1], elem_ref[2], elem)
        return elem

    elif elem_ref[0] == ElemRefArr:
        elem_ref[1][elem_ref[2]] = elem
        return elem