擅长:python、mysql、java
<p>在这里,您得到了函数的简化版本:</p>
<pre><code>import re
def analyzeCrawler2(thetext, text_to_search = "DEATH STAR"):
numchars = len(anhCrawler)
nospacechars = len(re.sub(r"\s+", "", anhCrawler))
numwords = len(anhCrawler.split())
dspos = anhCrawler.find(text_to_search)
return theReport.format(numchars, nospacechars, numwords, dspos)
print analyzeCrawler2(theReport)
This text contains 520 characters (434 if you ignore spaces).
There are approximately 87 words in the text. The phrase
DEATH STAR occurs and starts at position 261.
</code></pre>
<p>我认为技巧部分是从字符串中删除空格并计算非空格字符数。这可以通过使用正则表达式来实现。其余的应该是不言而喻的。在</p>