Find max() value using for loop not working in python

The values from “testname.txt” has been appended to the following lists.
f = open ( “testname.txt” , “r” )

list1 = [ 20 , 40 , 60 , 80 , 40 ]

list2 = [ 50 , 60 , 70 , 40 , 30 , 60 ]

list3 = [ 40 , 60 , 70 , 80 , 30 , 50 ]

list4 = [ 20 , 50 , 60 , 70 , 40 , 60 ]

r = 0

for j in f:

if r = = 0 :

r = 1

k = j.split()

list_names = [] #will hold the list names

list_names.append(k[ 1 ])

list_names.append(k[ 2 ])

list_names.append(k[ 3 ])

list_names.append(k[ 4 ])

else :

w = j.split()

list_highest = []

list_highest.append(w[ 1 ])

list_highest.append(w[ 2 ])

list_highest.append(w[ 3 ])

list_highest.append(w[ 4 ])

print ( "The highest values of" ,list_names[j], "=" , max (list_highest)) `#, max(list_highest)) ==> is not working

Any alternates to find max() of each list elements?
Any help would be appreciated.

The values from “testname.txt” has been appended to the following lists.

I believe the contents are not necessary to pinpoint on the question.
however I am adding it below.

name sub1 sub2 sub3 sub4

mark 20 50 40 20
teo 40 60 60 50
jain 60 70 70 60
lue 80 40 80 30
hed 40 30 30 40

The code is formatted and pasted below.

f = open ( "testname.txt" , "r" )
list1 = [ 20 , 40 , 60 , 80 , 40 ]
list2 = [ 50 , 60 , 70 , 40 , 30 ]
list3 = [ 40 , 60 , 70 , 80 , 30 ]
list4 = [ 20 , 50 , 60 , 70 , 40 ]
r = 0
for j in f:
    if r = = 0 :
        r = 1
        k = j.split()   # 'i' variable was a typo 
        list_names = [] #will hold the list names
        list_names.append(k[ 1 ])
        list_names.append(k[ 2 ])
        list_names.append(k[ 3 ])
        list_names.append(k[ 4 ])
    else :
        w = j.split()
        list_highest = []
        list_highest.append(w[ 1 ])
        list_highest.append(w[ 2 ])
        list_highest.append(w[ 3 ])
        list_highest.append(w[ 4 ])
        print ( "The highest values of" ,list_names[j], "=" , max (list_highest))  #, max(list_highest)) ==> is not working

Q: Let me know if there is any ways to print the max() elements in the loop.

Hope this would work. Let me know if any corrections.

f = open ( "testname.txt" , "r" )
list1 = [ 20 , 40 , 60 , 80 , 40 ]
list2 = [ 50 , 60 , 70 , 40 , 30 ]
list3 = [ 40 , 60 , 70 , 80 , 30 ]
list4 = [ 20 , 50 , 60 , 70 , 40 ]

r = 0
for j in f:
    if r == 0 :
        r = 1
        k = j.split()   # 'i' variable was a typo 
        list_names = [] #will hold the list names
        list_names.append(k[ 1 ])
        list_names.append(k[ 2 ])
        list_names.append(k[ 3 ])
        list_names.append(k[ 4 ])
    else :
        w = j.split()
        list_highest = []
        list_highest.append(w[ 1 ])
        list_highest.append(w[ 2 ])
        list_highest.append(w[ 3 ])
        list_highest.append(w[ 4 ])
        print ( "The highest values of" ,list_names[j], "=" , max (list_highest))

Any help would be greatly appreciated.

It should print max values in each rows/list, as below.

The highest value of “list1” is “80”.
The highest value of “list2” is “70”.
The highest value of “list3” is “80”.
The highest value of “list4” is “70”.

Hope that is simpler to understand. :slight_smile:
Thank you!

It works!!
Thank you very much.