<p>我正在尝试编写一小段代码来检测最常出现的字符。但是,我一直无法检测值是否为空格。你知道吗</p>
<p>下面是我的代码:</p>
<pre><code>text = "Hello World!"
## User lower() because case does not matter
setList = list(set(textList.lower()))
for s in setList:
if s.isalpha() and s != " ":
## Do Something
else:
setList.remove(s)
</code></pre>
<p>问题是集合列表以以下值结尾:</p>
<pre><code>[' ', 'e', 'd', 'h', 'l', 'o', 'r', 'w']
</code></pre>
<>我尝试了多种方法来检测空白区域,没有运气,包括在原始字符串值上使用String()。isspace()将不起作用,因为它至少查找一个字符。你知道吗</p>