<p>您可以使用正则表达式,在<a href="https://docs.python.org/2/library/re.html" rel="nofollow"><strong>^{<cd1>} module</strong></a>中实现</p>
<p><strong>更好的解决方案</strong></p>
<pre><code>>>> re.findall(r'[bcdfghjklmnpqrstvwxyz]+', "concertation", re.IGNORECASE)
['c', 'nc', 'rt', 't', 'n']
</code></pre>
<ul>
<li><p><code>[bcdfghjklmnprstvyz]+</code>匹配字符类中一个或多个字符的任意序列</p></li>
<li><p><code>re.IGNORECASE</code>对字符启用区分大小写匹配。那就是</p>
<pre><code>>>> re.findall(r'[bcdfghjklmnpqrstvwxyz]+', "CONCERTATION", re.IGNORECASE)
['C', 'NC', 'RT', 'T', 'N']
</code></pre></li>
</ul>
<hr/>
<p><strong>另一个解决方案</strong></p>
<pre><code>>>> import re
>>> re.findall(r'[^aeiou]+', "concertation",)
['c', 'nc', 'rt', 't', 'n']
</code></pre>
<ul>
<li><p><code>[^aeiou]</code>字符类被否定。匹配除此字符类中的字符以外的任何字符。简而言之就是匹配字符串中的辅音</p></li>
<li><p><code>+</code>量子化器<code>+</code>匹配字符串中出现的一个或多个模式</p></li>
</ul>
<p><strong>注意</strong>这也会在解决方案中找到非字母的相邻字符。因为字符类是除了元音以外的任何东西</p>
<p>示例</p>
<pre><code>>>> re.findall(r'[^aeiou]+', "123concertation",)
['123c', 'nc', 'rt', 't', 'n']
</code></pre>
<p>如果您确定输入始终包含字母表,则此解决方案是可以的</p>
<hr/>
<pre><code> re.findall(pattern, string, flags=0)
Return all non-overlapping matches of pattern in string, as a list of strings.
The string is scanned left-to-right, and matches are returned in the order found.
</code></pre>
<hr/>
<p>如果你想知道结果是如何得到的</p>
<p><code>re.findall(r'[bcdfghjklmnpqrstvwxyz]+', "concertation")</code></p>
<pre><code>concertation
|
c
concertation
|
# o is not present in the character class. Matching ends here. Adds match, 'c' to ouput list
concertation
|
n
concertation
|
c
concertation
|
# Match ends again. Adds match 'nc' to list
# And so on
</code></pre>