def binary_search(li, targetValue):
low, high = 0, len[li] #error on this line
while low <= high:
mid = (high - low)/2
if li[mid] == targetValue:
return "we found it!"
elif li[mid] > targetValue:
low = mid - 1;
elif li[mid] < targetValue:
high = mid + 1;
print "search failure "
最近刚刚发布了这个问题,但我的代码仍然不起作用?
最佳答案
你用错了括号 len(li)
而不是 len[li]
请记住,当您尝试访问一个函数时,您需要使用 function(args)
,如果您使用 []
,您实际上是在访问一个序列,如列表。 你的列表[索引]
。 len 是内置函数,因此您需要 ()
关于python - “builtin_function_or_method”对象不可订阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19989606/