how can I do something like this?
string = "ABFFFBFFFFFBF"
letter = "F"
maximum occurrence of F is FFFFF so output is: 5
anyone help?
>Solution :
There is probably a more Pythonic way to do this, but this function will do the job:
def maxConsecutiveOccurrences(letter, string):
count = 0
maxCount = 0
for ch in string:
if ch == letter:
count += 1
else:
count = 0
if count > maxCount:
maxCount = count
return maxCount
maxConsecutiveOccurrences("F", "ABFFFBFFFFFBF") returns 5