classSolution:defFirstNotRepeatingChar(self,s):'''
1、字典存储字符和出现次数(字符:次数)
2、将字典存储到列表中,遍历列表找出第一个次数为1的字符输出
:param string:
:return:
'''
dict = {}
for str in s:
if str notin dict.keys():
dict[str] = 1else:
dict[str] += 1
list = [item for item in dict.items()]
for tuple in list:
if tuple[1] == 1:
index = s.index(tuple[0])
return index
breakreturn -1if __name__ =='__main__':
c = Solution()
print(c.FirstNotRepeatingChar('NXWtnzyoHoBhUJaPauJaAitLWNMlkKwDYbbigdMMaYfkVPhGZcrEwp'))