I have a strings like this:
string1 = "foo_bar_of_foo"
string2 = "foo_bar"
This answer tells me how to check for an instance of "foo" in a string, but what if I want to check for exactly n instances of "foo" in a string?
for example:
#pseudo-code = find(2 instances of foo)
if "foo" in string1:
print("true") #this should print
if "foo" in string2:
print("false") #this shouldn't print since string2 only has 1 instance of foo
I can think of long and complicated ways of doing this, but I was wondering what the pythonic approach would be?