def run_length_encode(data):
    """ Encodes the input data using the RLE method.

    See: https://en.wikipedia.org/wiki/Run-length_encoding

    Args:
        data: list, corresponding to the input data.

    Returns:
        list, result of the compression.
    """
    val = data[0]
    count = 1
    compressed_data = []

    for i in range(1, len(data)):
        if data[i] == data[i-1]:
            count += 1
        else:
            compressed_data.extend([count, val])
            val = data[i]
            count = 1

    compressed_data.extend([count, val])
    return compressed_data