+ 1

find max in a list, python

hello, I want to open a file and read the content then find max numbers but the code below just prints the length of numbers, not number itself. list = open ("D:\mass.txt", "r") cont = list.read() top = max(cont) for i in cont: print(top) ~~~~~result~~~~~ 4 4 4 4 4 4 Thank you.

12th Nov 2017, 9:51 AM
Dariush Shiri
Dariush Shiri - avatar
5 Respuestas
+ 8
delete this line: for i in cont:
12th Nov 2017, 9:56 AM
Kamil
Kamil - avatar
+ 7
yeah, thats the max number isn't that what you want?
12th Nov 2017, 10:01 AM
Kamil
Kamil - avatar
+ 7
Oh I see, I'm not an expert in python :/ answer from stack overflow: numbers = [float(line[67:71].rstrip()) for line in input_file] largest_num = max(numbers) smallest_num = min(numbers) total = sum(numbers) count = len(numbers) https://www.google.at/url?sa=t&source=web&rct=j&url=https://stackoverflow.com/questions/28618342/find-min-and-max-from-text-file-python&ved=0ahUKEwjCi-C857jXAhXSqKQKHfJXA8wQjjgIJTAA&usg=AOvVaw3caF7dt6YvsUEWGTwLvNHO
12th Nov 2017, 10:20 AM
Kamil
Kamil - avatar
+ 2
deleted, output: 4 :| instead of a bunch of 4s just one 4.
12th Nov 2017, 9:59 AM
Dariush Shiri
Dariush Shiri - avatar
+ 2
absolutely not. the max number should be like 9823
12th Nov 2017, 10:10 AM
Dariush Shiri
Dariush Shiri - avatar