import itertools


def run_length_encode(tags_to_encode):
    """Perform run length encoding.

    Args:
        tags_to_encode: A string, usually of DeletionTags.

    Returns:
        the RLE string. For example, if the input was NNNNNCNNTTC,
            the function would return 5N1C2N2T1C
    """

    rle_list = [(len(list(g)), str(k))
                for k,g in itertools.groupby(tags_to_encode)]
    rle_string = ''.join([(str(n) if n > 1 else '') + str(c) for n, c in rle_list])
    return rle_string