安全问答

安全问答是一个知识全球问答,包含丰富的问答知识

首页 常规 游戏 娱乐 科技 程序员

Python 查找字符串中第一个只出现一次的字符

  • 日期: 2024-06-05
  • 标签: 常规
def find_first_non_repeating_char(s):
    char_counts = {}
    for char in s:
        if char in char_counts:
            char_counts[char] += 1
        else:
            char_counts[char] = 1
    for char in s:
        if char_counts[char] == 1:
            return char
    return 'No'

s = input()
print(find_first_non_repeating_char(s))
Python 查找字符串中第一个只出现一次的字符

原文地址: https://www.cveoy.top/t/topic/ocvI 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录

  • 上一篇: 讣告:含义、内容和发布方式
  • 下一篇: 人类干预自然选择:利弊权衡与规范思考

© 2019 • 2025 - 安全问答 站长邮箱:wxgpt@qq.com    ICP备案/许可证号:豫ICP备2024104334号-2