Longest stretch without repeats

Find the length of the longest stretch of a string with no repeated characters. Keep a window [left, right] and a set of the characters in it. Move right one step at a time; if the new character is already in the set, move left rightwards, removing characters from the set, until it is not. The window is then valid again; record its length.

Write longest_unique(text).

longest_unique("abcabcbb")  ->  3
longest_unique("bbbbb")     ->  1
longest_unique("")          ->  0
def longest_unique(text):
    ...