栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python练习-Python输出不重复的字符

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python练习-Python输出不重复的字符

#Python输出不重复的字符

#输入一个字符串,把最左边的10个不重复的字符(大小写算不同字符)挑选出来
#如果不重复的字符不到10个,则按实际数目输出
#输入格式:输入一个字符串s
#输出格式:输出一个字符串,包含字符串s最左边10个不重复的字符
#输入样例1:Hello world , hello python
#输出样例1:Helo wrd,h

def unique(s):
    set1 = set([])
    out = ""
    for i in range(len(s)):
        c = s[i]
        if c not in set1:
            out = out + c
            set1.add(c)
    return out[0:10]
def main():
    string = "Hello world , hello python"
    ret = unique(string)
    print(ret)
if __name__ == '__main__':
    main()

运行结果:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/339801.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号