On 07/09/2010 01:44, Xavier Ho wrote:
On 7 September 2010 10:37, ceycey <[email protected] <mailto:[email protected]>> wrote: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']. How can I convert the elements of list to float so max function finds the correct answer. >>> input = ['3.4225', '7.7284', '10.24'] >>> [float(x) for x in input] [3.4225, 7.7284, 10.24]
If you wanted to find the maximum value without converting the list to numbers you could do this: >>> input = ['3.4225', '7.7284', '10.24'] >>> max(input, key=float) '10.24' Incidentally, there's a builtin function called 'input' so using it as a variable name is a discouraged! :-) -- http://mail.python.org/mailman/listinfo/python-list
