擅长:python、mysql、java
<p>您缺少第二个元素,因为您正在使用<code>return</code>语句</p>
<p>相反,请使用以下内容</p>
<pre><code>mylist = [595, 595, 344, 344, 628, 628, 628, 353, 353, 353, 353, 353]
newlist = []
def has1dup(lst):
setlst = list(set(lst)) # no duplicate elements
for i in range(len(setlst)): # while the setlist's element count,
if lst.count(setlst[i]) == 2: # if the count of setlist[i] of lst is bigger than 1
newlist.append(setlst[i])
has1dup(mylist)
print(newlist)
</code></pre>
<p>输出</p>
<pre><code>[344, 595]
</code></pre>
<p>现在在上面的例子中,我们声明了一个名为<code>newlist</code>的新列表。对于集合中其在列表中的计数恰好为<code>2</code>的每个元素,我们将其附加到一个新列表中</p>