简体   繁体   English

Python:max不带关键字参数

[英]Python: max takes no keyword arguments

I am trying to print the max of two lists as such: 我正在尝试这样打印两个列表的最大值:

print max([3,4,5,0]), max([3,4,-5,0], key = abs)

and I get the error "max() takes no keyword arguments" 我收到错误"max() takes no keyword arguments"

I'm using Python 2.4.3 我正在使用Python 2.4.3

What's going on? 这是怎么回事?

Thanks! 谢谢!

You are using a python feature not yet supported in Python 2.4. 您正在使用Python 2.4中尚不支持的python功能。 From the max() documentation : max()文档中

Changed in version 2.5: Added support for the optional key argument. 在版本2.5中进行了更改:添加了对可选key参数的支持。

You'll have to use a decorate, undecorate pattern, using a python list comprehension: 您将必须使用装饰性的,未装饰性的模式,以及python列表理解功能:

max([(abs(i), i) for i in [3,4,-5,0]])[1]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM