How to convert a list of strings to a tuple of floats?

Ulrich Eckhardt eckhardt at satorlaser.com
Mon May 18 04:06:48 EDT 2009


boblatest at googlemail.com wrote:
> this is the conversion I'm looking for:
> 
> ['1.1', '2.2', '3.3'] -> (1.1, 2.2, 3.3)
> 
> Currently I'm "disassembling" the list by hand, like this:
> 
>     fields = line.split('; ')
>     for x in range(len(fields)):
>         fields[x] = float(fields[x])
>     ftuple = tuple(fields)
> 
> Of course it works, but it looks inelegant.

temp = map(float, x)
ftuple = tuple(temp)

Of course this is also possible to write in a single line.

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932




More information about the Python-list mailing list