converting lists to strings to lists

gry at ll.mit.edu gry at ll.mit.edu
Wed Apr 12 10:19:09 EDT 2006


Read about string split and join.  E.g.:
l = '0.870000 0.250000 0.790000'
floatlist = [float(s) for s in l.split()]

In the other direction:
floatlist = [0.87, 0.25, 0.79000000000000004]
outstring = ' '.join(floatlist)

If you need to control the precision(i.e. suppress the 00004), read
about
the string formatting operator "%".

-- George Young




More information about the Python-list mailing list