Light Mode
Dark Mode
Explanation "Count Substring Occurrences"

Hello, I'm a beginner, I don't understand this lines :

ind = res = 0 and while (ind:= mainstr.find(substr, ind))!= -1:

in this code : ind = res = 0 mainstr = mainstr.lower() substr = substr.lower() while (ind:= mainstr.find(substr, ind))!= -1: res += 1 ind += 1

return res

Why do you create res ? Is ind not enought ?

  • code_review
  • feedback
  • python
Created: June 16, 2025, 8:26 p.m.
Updated: June 16, 2025, 8:27 p.m.
0
6
User avatar
TH2O