List of strings to list of floats ?

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Mon Oct 17 17:52:27 EDT 2005


Erik Max Francis:
>result = [sqrt(x**2 + y**2) for x, y in zip(xs, ys)]

Another possibility:

from math import hypot
result = [hypot(*xy) for xy in zip(xs, ys)]

Or better:
from math import hypot
result = map(hypot, xs, ys)

bearophile




More information about the Python-list mailing list