List comprehension and string conversion with formatting
Jaime Fernandez del Rio
jaime.frio at gmail.com
Tue Jun 9 11:48:55 EDT 2009
On Tue, Jun 9, 2009 at 5:38 PM,
stephen_b<redplusbluemakespurple at gmail.com> wrote:
> I'd like to convert a list of floats to a list of strings constrained
> to one .1f format. These don't work. Is there a better way?
>
> [".1f" % i for i in l]
> or
> [(".1f" % i) for i in l]
There's a missing %, this does work...
["%.1f" % i for i in l]
Jaime
--
(\__/)
( O.o)
( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus
planes de dominación mundial.
More information about the Python-list
mailing list