<p>我建议你先创建一个所有元音的列表:</p>
<p><code>vowels = ['a','e','i','o','u']</code></p>
<p>好吧,字母列表(Char)实际上和字符串是一样的,所以我只需要做以下操作:</p>
<p><code>vowels = "aeiou"</code></p>
<p>在那之后,我会试着把你的字串分成几个字。让我们试试乔兰·比斯利建议的<code>tw.split()</code>。它返回:</p>
<p><code>['BenSasse,', 'well', 'I', 'did', 'teach', 'her', 'the', 'bend-and-snap', 'https://twitter.com/bethanyshondark/status/903301101855928322', 'QT', '@bethanyshondark', 'Is', 'Reese', 'channeling', '@BenSasse', 'https://acculturated.com/reese-witherspoons-daughter-something-many-celebrity-children-lack-work-ethic/', ',', 'Twitter', 'for', 'Android']</code></p>
<p>你能接受这句话吗?请注意,每个链接都是一个“单词”。我想这没问题。你知道吗</p>
<p>如果我们用for循环访问每个单词,我们就可以用内部for循环访问每个字母。但是在我们开始之前,我们需要跟踪所有接受的3个或更多元音的单词,所以做一个新的列表:<code>final_list = list()</code>。现在:</p>
<pre><code>for word in tw.split():
counter=0 # Let's keep track of how many vowels we have in a word
for letter in word:
if letter in vowels:
counter = counter+1
if counter >= 3:
final_list.append(word) # Add the word if 3 or more vowels.
</code></pre>
<p>如果您现在打印:<code>print(final_list)</code>您应该得到:</p>
<p><code>['BenSasse,', 'bend-and-snap', 'https://twitter.com/bethanyshondark/status/903301101855928322', '@bethanyshondark', 'Reese', 'channeling', '@BenSasse', 'https://acculturated.com/reese-witherspoons-daughter-something-many-celebrity-children-lack-work-ethic/']</code></p>