<br><br>On Wednesday, April 25, 2018, Steven D'Aprano <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Wed, Apr 25, 2018 at 11:22:24AM -0700, Julia Kim wrote:<br>
> Hi,<br>
> <br>
> There’s an error with the string method count().<br>
> <br>
> x = ‘AAA’<br>
> y = ‘AA’<br>
> print(x.count(y))<br>
> <br>
> The output is 1, instead of 2.<br>
<br>
Are you proposing that there ought to be a version of count that looks <br>
for *overlapping* substrings?<br>
<br>
When will this be useful?</blockquote><div><br></div><div>"Finding a motif in DNA"</div><div><a href="http://rosalind.info/problems/subs/">http://rosalind.info/problems/subs/</a><br></div><div> </div><div>This is possible with re.find, re.finditer, re.findall, regex.findall(, overlapped=True), sliding window</div><div><a href="https://stackoverflow.com/questions/2970520/string-count-with-overlapping-occurrences">https://stackoverflow.com/questions/2970520/string-count-with-overlapping-occurrences</a><br></div><div><br></div><div>n-grams can be by indices or by value.</div><div>count = len(indices)</div><div><a href="https://en.wikipedia.org/wiki/N-gram#Examples">https://en.wikipedia.org/wiki/N-gram#Examples</a><br></div><div><br></div><div><a href="https://en.wikipedia.org/wiki/String_(computer_science)#String_processing_algorithms">https://en.wikipedia.org/wiki/String_(computer_science)#String_processing_algorithms</a><br></div><div><br></div><div><a href="https://en.wikipedia.org/wiki/Sequential_pattern_mining">https://en.wikipedia.org/wiki/Sequential_pattern_mining</a><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
-- <br>
Steve<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
</blockquote>