Python类型错误:'List'对象不可调用

Wag*_*CDR 0 python list

我用这个Python27的小代码内容得到了这个错误.谁能帮我这个?提前致谢.

运行时错误回溯(最近一次调用最后一次):文件"5eb4481881d51d6ece1c375c80f5e509.py",第57行,在print len(arr)中TypeError:'list'对象不可调用

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    
Run Code Online (Sandbox Code Playgroud)

kin*_*all 5

您已经创建了一个名为的列表len,您可以从此处看到,您可以将其编入索引:

len[i] = input()
Run Code Online (Sandbox Code Playgroud)

很自然地,len它不再是一个获取列表长度的函数,导致您收到错误.

解决方案:将len列表命名为其他内容.