Is this algorithm of constant time? I have the following code in Python:

def is_unique(string):
    if len(string) &lt;= 1:
        return True

    if len(string) &gt; 128:
        return False

    char_set = defaultdict(lambda: False)

    for char in string:
        if not char_set[char]:
            char_set[char] = True
        else:
            return False

    return True


It's basically checking if a string is unique or not. I think that my algorithm is O(1):

No matter what it's the length of the string, I will only iterate over at most 128 times in the worst case. All the operations (len, dict lookup etc) are of constant time as well.

I guess my generic question here is if you can proof that your algorithm will always iterate for a constant number of times, can you claim that this is O(1)?
Under the assumptions you've stated, yes, the code runs in constant time.  The running time for any string can't be longer than the running time for a 128-character string, which is some constant number of steps.