python列表中存类对象为什么不能打印,Python类型错误:“列表"对象不可调用

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

解决方案

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.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值