Create a Python function to detect if a string contains a duplicate character.
def contains_duplicate(s):
    counts = dict()
    for ch in s:
        if ch in counts:
            return True
        counts[ch] = 1
    return False