+ 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.
5 Answers
+ 8
delete this line:
for i in cont:
+ 7
yeah, thats the max number
isn't that what you want?
+ 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
+ 2
deleted, output: 4 :|
instead of a bunch of 4s just one 4.
+ 2
absolutely not. the max number should be like
9823