Python | Min/Max value in float string list
ometimes, while working with a Python list, we can have a problem in which we need to find min/max value in the list. But sometimes, we don’t have a natural number but a floating-point number in string format. This problem can occur while working with data, both in web development and Data Science domain. Let’s discuss a way in which this problem can be solved.
Method : Using min()/max() + float()
This problem can be solved using the min or max function in which we first convert the strings into float and then pass this logic in functions in respective min/max function.
Method : Using min()/max() + float()
This problem can be solved using the min or max function in which we first convert the strings into float and then pass this logic in functions in respective min/max function.
Python3
# Python3 code to demonstrate working of# Min / Max value in float string list# using min()/max() + float() + generator# initialize liststest_list = ['4.5', '7.8', '9.8', '10.3']# printing original listprint("The original list is : " + str(test_list))# Min / Max value in float string list# using min()/max() +float + lambda functionres_min = min(test_list,key=lambda x:float(x))res_max = max(test_list,key=lambda x:float(x))# printing resultprint("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



.png)