【发布时间】:2016-10-28 21:49:44
【问题描述】:
在 python 中,我得到一个“TypeError: 'int' obejct is not callable”。我已经阅读了其他帖子,但我仍然无法弄清楚为什么会这样。
def sort_last(tuples):
sorted_tuples = [sorted(tuples,key=tuple[-1]) for tuple in tuples]
return sorted_tuples
然后我得到:“TypeError: 'int' object is not callable.”感谢任何建议和评论
【问题讨论】:
-
感谢您展示一些代码,但您能否展示一下您是如何实例化
tuples对象的?提供一些示例数据。 -
缩进代码的第三行。
-
如果此代码中出现错误,那么您一定是不小心将
sorted重新分配给了一个整数。将您的变量sorted更改为_sorted之类的东西,您应该会很好。 -
tuple[-1]不是函数。 -
改为使用
key=lambda x: x[-1]并缩进return
标签: python