擅长:python、mysql、java
<p>您不需要拆分原始字符串,因为在Python中循环字符串会迭代字符串的字符</p>
<p>使用<a href="https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions" rel="nofollow noreferrer">list comprehension</a>,您只需检查当前字符<code>char</code>是否是元音,并在这种情况下排除它</p>
<p>然后,在最后,您可以再次连接字符串</p>
<pre><code>a = 'the quick brown fox jumps over the lazy dog'
s = [char for char in a if char not in ('a', 'e', 'i', 'o', 'u')]
print(''.join(s))
# th qck brwn fx jmps vr th lzy dg
</code></pre>
<p>如果您的句子可能包含大写元音,并且希望过滤掉这些元音,您可以使用<a href="https://docs.python.org/3/library/stdtypes.html?highlight=str%20lower#str.lower" rel="nofollow noreferrer">^{<cd2>}</a>:</p>
<pre><code>s = [char for char in a if char.lower() not in ('a', 'e', 'i', 'o', 'u')]
</code></pre>