Python类型错误:“列表"对象不可调用 [英] Python Type Error: 'List' object is not callable
问题描述
我在Python27的这一小段代码内容中遇到了此错误.谁能帮我这个?预先感谢.
I'm getting this error with this small code content of Python27. Can anyone help me with this? Thanks in advance.
运行时错误回溯(最近一次通话最后一次):文件"5eb4481881d51d6ece1c375c80f5e509.py",第57行,在打印len(arr)TypeError:列表"对象不可调用
Run Time Error Traceback (most recent call last): File "5eb4481881d51d6ece1c375c80f5e509.py", line 57, in print len(arr) TypeError: 'list' object is not callable
global maximum
def _lis(arr , n ):
# to allow the access of global variable
global maximum
# Base Case
if n == 1 :
return 1
# maxEndingHere is the length of LIS ending with arr[n-1]
maxEndingHere = 1
"""Recursively get all LIS ending with arr[0], arr[1]..arr[n-2]
IF arr[n-1] is maller than arr[n-1], and max ending with
arr[n-1] needs to be updated, then update it"""
for i in xrange(1, n):
res = _lis(arr , i)
if arr[i-1] < arr[n-1] and res+1 > maxEndingHere:
maxEndingHere = res +1
# Compare maxEndingHere with overall maximum. And
# update the overall maximum if needed
maximum = max(maximum , maxEndingHere)
return maxEndingHere
def lis(arr):
# to allow the access of global variable
global maximum
# lenght of arr
n = len(arr)
# maximum variable holds the result
maximum = 1
# The function _lis() stores its result in maximum
_lis(arr , n)
return maximum
num_t = input()
len = [None]*num_t
arr = []
for i in range(0,num_t):
len[i] = input()
arr.append(map(int, raw_input().split()))
print len(arr)
break
推荐答案
您已经创建了一个名为 len
的列表,从这里可以看到以下事实:您可以对其进行索引:>
You have created a list named len
as you can see here from the fact that you're able to index it:
len[i] = input()
很自然地, len
不再是获取列表长度的函数,从而导致您收到错误消息.
So naturally, len
is no longer a function that gets the length of a list, leading to the error you receive.
解决方案:为您的 len
列表命名.
Solution: name your len
list something else.
这篇关于Python类型错误:“列表"对象不可调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!