Is there a command that returns the number of substrings in a string?
Gerard Flanagan
grflanagan at gmail.com
Tue Oct 27 03:31:22 EDT 2009
alex23 wrote:
> Gerard Flanagan <grflana... at gmail.com> wrote:
>> def count(text, *args):
>
> Other than the ability to handle multiple substrings, you do realise
> you've effectively duplicated str.count()?
I realise that calling this count function with a single argument would
be functionally identical to calling str.count(), yes. But I can imagine
the situation of wanting to find multiple (disjoint) substrings. Is
there a reason for preferring multiple calls to str.count() in such a
case? Or is there a more obvious approach?
> Gerard Flanagan <grflana... at gmail.com> wrote:
> re.findall?
Forget that, that was stupid.
More information about the Python-list
mailing list