Minimum and Maximum of a list containing floating point numbers
ceycey
cuneyt.ertal at gmail.com
Mon Sep 6 20:37:33 EDT 2010
I have a list like ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881',
'1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.7689', '1.7689',
'3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601', '9.0601',
'9.0601']. What I want to do is to find minimum and maximum number in
this list.
I used min function,
s = ['1.1881', '1.1881', '1.1881', '1.1881', '1.1881', '1.1881',
'1.1881', '1.1881', '1.1881', '1.1881', '1.7689',
'1.7689', '3.4225', '7.7284', '10.24', '9.0601', '9.0601', '9.0601',
'9.0601', '9.0601']
print min(s)
print max(s)
these gives me
1.181
9.0601
maximum value is wrong. It must be 10.24.
I know why max function gives wrong number. Because max function
processed elements of list as strings. How can I convert the elements
of list to float so max function finds the correct answer.
I hope I can explain my problem.
Cuneyt.
More information about the Python-list
mailing list