Re: List comprehension and string conversion with formatting

2009-06-09 Thread stephen_b
On Jun 9, 10:43 am, Carl Banks wrote: > You need a % in there, chief. > > Carl Banks You are so right. Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: List comprehension and string conversion with formatting

2009-06-09 Thread Jaime Fernandez del Rio
On Tue, Jun 9, 2009 at 5:38 PM, stephen_b 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

Re: List comprehension and string conversion with formatting

2009-06-09 Thread Carl Banks
On Jun 9, 8:38 am, stephen_b 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] You need a % in there, chief. [ "%.1f" % x for x in lst ] BTW, I t