<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>
<pre><code>In [1]: l = 'Is that what you mean'.split()
In [2]: [word for word in l if len(word) == max(map(len, l))]
Out[2]: ['that', 'what', 'mean']
</code></pre>