Method: Using min () / max () + float ()
This problem can be solved with the min function
or max
in which we first convert strings to floating point, and then pass this logic to functions in the corresponding min / max function.
# Python3 code to demonstrate how it works # Min. / Max. Value in floating point string list # using min () / max () + float () + generator # initialize lists test_list = [ ’4.5’ , ’7.8’ , ’ 9.8’ , ’10.3’ ] # print original list print ( "The original list is:" + str (test_list)) # Min. / Max. Value in floating point string list # using min () / max () + float () + generator res_min = min ( float (sub) for sub in test_list) res_max = max ( float (sub) for sub in test_list) # print result print ( " The min value of list: " + str ( res_min)) print ( "The max value of list: " + str (res_max)) |
Output:
The original list is: [’4.5’,’ 7.8’, ’9.8’,’ 10.3’] The min value of list: 4.5 The max value of list: 10.3
Python | Min. / Max. The value in a floating point list of strings Python functions: Questions
Python | Min. / Max. The value in a floating point list of strings String Variables: Questions