In Python, how do I convert all of the items in a list to floats? In Python, how do I convert all of the items in a list to floats? python python

In Python, how do I convert all of the items in a list to floats?


[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.


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.)


This would be an other method (without using any loop!):

import numpy as nplist(np.float_(list_name))