擅长:python、mysql、java
<p>这将完成以下工作:</p>
<pre><code>l=('click', 'bait', 'carrot', 'juice')
def f(l):
s=set()
for i in l:
if i[0] in s:
return False
s.add(i[0])
return True
</code></pre>
<p>集合<code>s</code>由迄今为止看到的第一个字母组成。在每次迭代中,您移动到下一个单词并检查第一个字母是否在<code>s</code>中。如果存在,则返回<code>False</code>。否则,将第一个字母添加到<code>s</code>并继续。循环的优点是,如果第一个字母提前重复,则停止迭代而不继续。从而避免不必要的工作</p>