def firstUniqChar(s): data = {} for i in range(len(s)): if s[i] not in data: data[s[i]] = i else: data[s[i]] = -1 for i in data.values(): if i >= 0: return i return -1