【Codewars python 5kyu】: First non-repeating character

本文介绍了一个 Codewars 上的 Python 5kyu 问题——找到字符串中第一个不重复的字符。函数需考虑大小写相同视为同一字符,并保持原始字母的大小写。若所有字符都重复,返回空字符串。
摘要由CSDN通过智能技术生成

问题描述:

Write a function named first_non_repeating_letter that takes a string input, and returns the first character that is not repeated anywhere in the string.

For example, if given the input 'stress', the function should return 't', since the letter t only occurs once in the string, and occurs first in the string.

As an added challenge, upper- and lowercase letters are considered the same character, but the function should return the correct case for the initial letter. For example, the input 'sTreSS'should return 'T'.

If a string contains all repeating characters, it should return an empty string ("") or None -- see sample tests.

代码实现:

#codewars第十二题
def first_non_repeating_letter(string):
    #your code here
    my_str = string.u
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值