import re


def split(string, delim):
    """
    Splits the given string on given delimiter and returns a list of substrings
    that contains the delimiters as well. The number of elements in the list is
    always even.
    """

    if string is None:
        return None

    if len(string) == 0:
        return ["", ""]

    if delim is None or len(delim) == 0:
        return [string, ""]

    # Put the delimiter into parentheses to get the delimiters as well:
    # "A \n\n B \n\n C" -> ["A", "\n\n", "B", "\n\n", "C"].
    res = re.split("(%s)" % delim, string)

    # Make sure, that there is an even number of elements in list.
    if len(res) % 2 != 0:
        res.append("")

    return res