题解 | #计算某字符出现次数#
计算某字符出现次数
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
import sys # 1.定义一个空列表,把2行数据存进来 list1=[] for line in sys.stdin: a = line.split() list1.append(a) # 2.定义两个空字符串,把列表的2行数据分别提取成2个字符串个数 str1,str2='','' for i in list1[0]: str1=str1+i for i in list1[1]: str2=str2+i # 3.由于字符串的字符不区分大小写,所以这里统一转化为小写好比较 str1=str1.lower() str2=str2.lower() # 4.遍历字符串,看下字符是否在里面,如果有就累计值加一 count=0 for i in str1: if str2 ==i: count=count+1 print(count)