给定一个像“abbbd cdda cbaa”这样的字符串,你将如何确定特定字符(如“b”)出现次数最多的单词。我的初始代码:
sample = "abbbd cdda cbaa"
sample_splitter = sample.split()
#sample_splitter is now [abbbd, cdda, cbaa]
for word in sample_splitter:
word.count("b") #this returns the number of occurrences of the char b
max(word.count("b")) #this will return the highest number
我一直在弄清楚如何将字母的最高计数与与之关联的数组值相关联。在这种情况下,应该是“abbbd”