找到第一個只出現一次的字符並返回它的位置(Python)

 

s = 'hellobaby'
def findchar(s):
    for i in s:
        if s.count(i)==1:
            return i, s.index(i)
m,n=findchar(s)
print('第一個出現一次的字符是{},位置是{}'.format(m,n))

相關文章
相關標籤/搜索