2016-10-11 209 views
0

我收到了Python27这个小代码内容的错误。谁能帮我这个?提前致谢。Python类型错误:“列表”对象无法调用

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  
+0

不要将内建函数名称赋值给别的东西。 – Li357

+3

用你的变量'len'覆盖'len'函数。尝试使用另一个变量名称。 – acw1668

+0

@AndrewL。谢谢!只是想通了 –

回答

1

那就是当你定义一个变量,它也内置函数名称会发生​​什么。
将变量len更改为其他值。

5

您创建了一个名为len列表,你可以从一个事实,即你能看到指数在这里:

len[i] = input() 

所以很自然的,len不再是获得的长度的函数列表,导致您收到的错误。

解决方法:将您的len命名为其他名称。

相关问题