On Sep 6, 10:31 pm, Steven D'Aprano <steve-REMOVE-
t...@cybersource.com.au> wrote:
> On Tue, 07 Sep 2010 11:00:45 +1000, Ben Finney wrote:
> > If you're going to use the list of float objects, you can convert them
> > all with a list comprehension.
> [...]
> >     >>> numbers_as_float = [float(x) for x in numbers_as_str]
>
> That's awfully verbose. A map is simpler:
>
> numbers_as_float = map(float, numbers_as_str)
>
> --
> Steven

In Python 3.x it has one disadvantage:

>>> numbers_as_float = map(float, numbers_as_str)
>>> max(numbers_as_float)
10.24
>>> min(numbers_as_float)
Traceback (most recent call last):
  File "<pyshell#21>", line 1, in <module>
    min(numbers_as_float)
ValueError: min() arg is an empty sequence
>>>
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to