def merge_after_element_on_condition(elements, element_conditions):
    """Merge elements.

    Ex.: If merged on conditions ['a'], ['a', 'b', 'c', 'a', 'e']
         becomes ['ab', 'c', 'ae']
    """
    for i in range(len(elements) - 2, -1, -1):
        if elements[i] in element_conditions:
            elements[i] = elements[i] + elements.pop(i + 1)

    return elements