2

I'm getting this error with this small code content of Python27. Can anyone help me with this? Thanks in advance.

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

2 Answers 2

6

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()

So naturally, len is no longer a function that gets the length of a list, leading to the error you receive.

Solution: name your len list something else.

Sign up to request clarification or add additional context in comments.

Comments

2

That is what happens when you define a variable that is also a built-in function name.
Change the variable len to something else.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.