<p>嘿,作为新手,我想知道如何从列表中找到多个最大值(即有多个最大值或相同长度的项)和最小值(与最大值相同的位置)。我试过使用<code>max</code>函数,但它只打印一个项,与<code>min</code>相同。这是对列表中字符串的长度进行的(例如,使用<code>len</code>)!</p>
<p>这是我到目前为止的密码</p>
<pre><code> def choice4(filelist):
try:
c4longest=max(filelist,key=len)
print(c4longest,"is the longest item in the list")
</code></pre>
<p>试试这个:</p>
<pre>
def choice4(filelist):
mymax = max(map(len,filelist))
return [a for a in filelist if len(a)==mymax]
a = ['joe','andy','mark','steve']
a.extend(a)
print choice4(a)
</pre>