• + 1 comment

    why did you add len(K)-1 . ?

    • + 0 comments

      match.start() + len(K) - 1

      len(K) tells us how many characters there are in K. We subtract 1 because indices in Python start from 0, so the last index of the match will be match.start() + len(K) - 1.