Given a string like “abbbd cdda cbaa”, how would you determine the word that has the highest occurrence of a specific character like “b”. My initial code:
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
I’m stuck in figuring out how to associate the highest count of the letter and the array value associated with it. In this case that should be “abbbd”
something like this: use
max()withstr.split():