import namedtuple
Count = namedtuple('Count', 'letter number')
def letter_count(a: str, b:str):
'''Takes String A and count how many times a letter appears in it'''
Countlist = []
letter= ''
for x in b:
letter = x
number=0
for y in a:
if y.lower() in x:
number+=1
Countlist.append(Count(letter, number))
return Countlist
代码应该像这样工作: print(letter_count('Princess','ps'))应该产生:
[Count(letter='p', number=0), Count(letter='s', number=1)]
但是,我已经设置了代码,因此它只对小写字母敏感,但会计算大写,所以我得到的结果是:
[Count(letter='p', number=1), Count(letter='s', number=1)]
如何使此代码对大写和小写字母都敏感?