Given a string, return n distinct characters with their respective counts, as well as the remainder of the string
I would avoid using indexes altogether and rely on iter to advance character by character and remember what's left in the string:

def enc_consume(carrier, nsyms):
    characters = defaultdict(int)
    stream = iter(carrier)

    for char in stream:
        characters[char] += 1
        if len(characters) &gt;= nsyms:
             break

    return characters, ''.join(stream)