printing with variable length of list
Alex Martelli
aleaxit at yahoo.com
Mon Oct 18 16:17:42 EDT 2004
les ander <les_ander at yahoo.com> wrote:
> Hi,
> suppose I have a list
> d=[1.2 , 31.1, 1.001]
> in general i will not know the size of d
> however, I would like to print them out nicely in the row format
> such as:
> print "%-10f "* len(d) % d
tuple(d) is one possibility, as Riccardo pointed out. A small loop
might also be nice, and conceptually simple:
for item in d:
print '%-10f'%item,
print
the comma at the end stops print from emitting a newline, and a space is
used between item; the print at the end ends the line.
Alex
More information about the Python-list
mailing list