TypeError: 'int' object is not callable
Hi Everyone I am new to Python programming, and my question is I have Three lists named Zeilen1, Zeilen2, and Zeilen3 all of them have some number of elements.
Now i have three lists named as l1, l2, and l3 containing length of Zeilen1, Zeilen2, and Zeilen3 respectively
And now, all lists l1, l2, and l3 are put as an element of the list Laengen.
I have used the max function to find the maximum length of the list Laengen, as well as the name of that particular list has a maximum length, but the program thoroughs an error which is TypeError: 'int' object is not callable
I’ll try to answer without an inbuilt max() function.
In the below program, I am using int_max in python. which will help to manually find the max value of the list.
Code:
#different number of elements inside each zeilen list
Zeilen1 = [1, 2,3,45, 3,7,5,6,7,8]
Zeilen2 = [7,8,9]
Zeilen3 = [6, 9,34,34,3,5,6,7,8,32,2]
l1 = len(Zeilen1)
l2 = len(Zeilen2)
l3 = len(Zeilen3)
Laengen = [l1, l2, l3]
#to print the exact Zeilen name which has the max element
Zeilen_names = ['Zeilen1', 'Zeilen2', 'Zeilen3']
int_max = -float('inf')
max_index = -1
for i, length in enumerate(Laengen):
if length > int_max:
int_max = length
max_index = i
print(f"The maximum length is: {int_max}")
print(f"This corresponds to: {Zeilen_names[max_index]}")
Output:
The maximum length is: 11
This corresponds to: Zeilen3