Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1
Because findall like i believe any other counting method can't be overlaping. Try this: import re a = re.compile(r"mama") print(a.findall("mamamama")) you could count it 1. "ma ma" ma ma 2. ma "ma ma" ma 3. ma ma "ma ma" but you only got 1 and 3 cuz 2 is part of both 1 and 3. you will get the same result with: text = "mamamama" i = text.count("mama") print(i) --> 2
17th Dec 2021, 5:20 AM
Piotr Ś
Piotr Ś - avatar