Find the first non-repeated character in a string

前端 未结 21 1583
有刺的猬
有刺的猬 2020-12-06 03:53

I read of a job interview question to write some code for the following:

Write an efficient function to find the first nonrepeated character in a st

21条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-06 04:26

    def firstnonrecur(word):
    
        for c in word:
            if word.count(c) == 1:
                print(c)
                break
    
    
    firstnonrecur('google')
    

    How about this?

提交回复
热议问题