Code to output the first repeated character in given string?

后端 未结 9 2141
日久生厌
日久生厌 2021-01-21 15:23

I\'m trying to find the first repeated character in my string and output that character using python. When checking my code, I can see I\'m not index the last character of my co

9条回答
  •  爱一瞬间的悲伤
    2021-01-21 15:42

    You can do this in an easier way:

    letters = 'acbdc'
    found_dict = {}
    for i in letters:
        if i in found_dict:
            print(i)
            break
        else:
            found_dict[i]= 1
    

    Output: c

提交回复
热议问题