Nov-24-2019, 03:29 PM
(Nov-24-2019, 02:14 PM)perfringo Wrote: Maybe I don't fully understand the problem. I assume that objective is to print rows integers maximum value. One can just:
with open('testname.txt', 'r') as f: header = next(f) for row in f: data = row.split() print(f"Maximum value on {data[0]}'s row is {max(data[1:], key=lambda x: int(x))}")If row number instead of name needed one can use enumerate and start at appropriate number (is header row #1?).
This code will output:
EDIT:
Output:Maximum value on mark's row is 50 Maximum value on teo's row is 60 Maximum value on jain's row is 70 Maximum value on lue's row is 80 Maximum value on hed's row is 40
It is also possible to split and assign names in one go. If appropriate names are used it can deliver better readability. Also no need for lambda, int can be called directly.
name, *values = row.split() # name is string and values is list print(f"Maximum value on {name}'s row is {max(values, key=int)}")
Thank you for your assistance.
TuxAndrew
Linux - RedHat,cPANEL CentOS,Ubuntu,Azure/AWS Administrator,
Assistance, Analysis and Diagnosis. Skype: tuxandrew,
[email protected]
Linux - RedHat,cPANEL CentOS,Ubuntu,Azure/AWS Administrator,
Assistance, Analysis and Diagnosis. Skype: tuxandrew,
[email protected]