Cha*_*rdy 1 python list max minimum
嘿,所以我是NEWBY我想知道如何从列表中找到多个最大值(即,有多个最大值或相同长度的项目)和最小值(与最大值相同).我已经尝试过使用这个max功能,但它只打印了一个项目,同样的min.它将在列表中的字符串长度(例如使用len)中完成!
这是我到目前为止的代码
def choice4(filelist):
try:
c4longest=max(filelist,key=len)
print(c4longest,"is the longest item in the list")
Run Code Online (Sandbox Code Playgroud)
试试这个:
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)