Dec-20-2019, 10:25 PM
(This post was last modified: Dec-21-2019, 01:11 AM by ichabod801.)
count_cat = 0 count_dog = 0 for i in range(len(str)-2): if str[i:i+3] == 'dog': count_dog += 1 if str[i:i+3] == 'cat': count_cat += 1 return count_cat == count_dogCan someone explain the purpose of the -2 in the for loop?