码迷,mamicode.com
首页 > 编程语言 > 详细

找到第一个只出现一次的字符并返回它的位置(Python)

时间:2017-06-26 23:52:48      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:class   nbsp   oba   位置   ges   for   turn   技术分享   pytho   

 

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))

技术分享

 

找到第一个只出现一次的字符并返回它的位置(Python)

标签:class   nbsp   oba   位置   ges   for   turn   技术分享   pytho   

原文地址:http://www.cnblogs.com/UncleYong/p/7082893.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!