s = [' From ',' Moscow ', 'to ' ,' the ' ,' Siberian ',' oil ',' capital ',' of ,' Novosibirsk ' ,' and ,' from ',' the ',' intelectual ',' hub ',' of ,‘ St ',' Petersburg ',' to ' , ' the ', ' nuclear ', ' submarine ' ,' base ',' of ' ,' Murmansk ',' Russians ',' are ', 'searching ',' for ',' a ',' way ' ,' out ',' in ',' anticipation ',' of ',' a ',' grim ',' future ',' in ',' a ',' country ',' torn ',' apart ',' by isolation ', 'censorship ' ,' and ',
' belligerence .']
s1 = s.count("m")
s2 = s.count("M")
print("m出现的次数:",s1)
print("M出现的次数:",s2)
[' From ',' Moscow ', 'to ' ,' the ' ,' Siberian ',' oil ',' capital ',' of ,' Novosibirsk ' ,' and ,' from ',' the ',' intelectual ',' hub ',' of ,‘ St ',' Petersburg ',' to ' , ' the ', ' nuclear ', ' submarine ' ,' base ',' of ' ,' Murmansk ',' Russians ',' are ', 'searching ',' for ',' a ',' way ' ,' out ',' in ',' anticipation ',' of ',' a ',' grim ',' future ',' in ',' a ',' country ',' torn ',' apart ',' by isolation ', 'censorship ' ,' and ',
' belligerence .'].count('m')
为啥这两个代码跑出来都是0,怎么计算小m和大m的个数
s = [' From ',' Moscow ', 'to ' ,' the ' ,' Siberian ',' oil ',' capital ',' of ,' Novosibirsk ' ,' and ,' from ',' the ',' intelectual ',' hub ',' of ,‘ St ',' Petersburg ',' to ' , ' the ', ' nuclear ', ' submarine ' ,' base ',' of ' ,' Murmansk ',' Russians ',' are ', 'searching ',' for ',' a ',' way ' ,' out ',' in ',' anticipation ',' of ',' a ',' grim ',' future ',' in ',' a ',' country ',' torn ',' apart ',' by isolation ', 'censorship ' ,' and ',
' belligerence .']
s = "".join(s)
s1 = s.count('m')
s2 = s.count("M")
print("m出现的次数:",s1)
print("M出现的次数:",s2)
不知道你这个问题是否已经解决, 如果还没有解决的话: