擅长:python、mysql、java
<p>尽量遵循采购订单的逻辑,不要对结构进行额外更改。只需修复错误:</p>
<pre><code>def initials(phrase):
#words = phase.split()
result = ""
for word in phrase.split(): # break the words
result += word[0] # get the first letter of each word
return result
print(initials("United Nations")) # Should be: UN
print(initials("United States of America")) # Should be: USOA
</code></pre>
<p>可能有更多的python方法可以达到同样的效果,但这里试着回答PO的问题</p>
<p>或者只使用一个衬套,使用如下发电机:</p>
<pre><code>phrase = 'United Nations'
inits = ''.join(w[0] for w in phrase.split())' # `UN`
</code></pre>