题解 | #计算某字符出现次数#
计算某字符出现次数
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
s = input() target = input() dic_s = {} for i in s: if i not in dic_s: dic_s[i] = 1 else: dic_s[i] += 1 sum = 0 if target in dic_s: sum += dic_s[target] if '0' <= target <= '9': pass else: if chr(ord(target)+32) in dic_s: sum += dic_s[chr(ord(target)+32)] if chr(ord(target)-32) in dic_s: sum += dic_s[chr(ord(target)-32)] print(sum)
原始一点点的解法 文章被收录于专栏
尽量不借助面向对象的思想,自己去实习具体过程