Reputation: 63
I'm trying to compare sum of first and last element in a list, second to second last, and so on. The list has even number of numbers. But when I call the max() function on a list, it gives me an error. Help me
li = [12,31,51,72,93,11,132,151,172,144]
sum1 = []
for i in range(len(li)):
sum1.append(li[i] + li[len(li)-1-i])
print(sum1)
print(max(sum1))
and the error is:
TypeError Traceback (most recent call last)
<ipython-input-34-04d301659610> in <module>
5 sum1.append(li[i] + li[len(li)-1-i])
6 print(sum1)
----> 7 print(max(sum1))
8
TypeError: 'int' object is not callable
Upvotes: 0
Views: 401
Reputation: 17322
it is possible that you have shadowed the built-function, you can use:
print(__builtin__.max(sum1))
in this way you will use the max
function that you want
Upvotes: 1