In Python, how do I convert all of the items in a list to floats?
map(float, mylist)
should do it.
(In Python 3, map ceases to return a list object, so if you want a new list and not just something to iterate over, you either need list(map(float, mylist)
- or use SilentGhost's answer which arguably is more pythonic.)
[float(i) for i in lst]
to be precise, it creates a new list with float values. Unlike the map
approach it will work in py3k.