This code works, but reading posts on here I get the impression it is probably not a very \"Pythonic\" solution. Is there a better more efficient way to solve this specific
Another possible solution.
>>> a= 'almforeachalmwhilealmleandroalmalmalm' >>> len(a.split('alm')) - 1 6 >>> q = "abcghabchjlababc" >>> len(q.split("abc")) - 1 3
Why not use the count method of str?
count
str
>>> a = "abcghabchjlababc" >>> a.count("abc") 3