variable length print format
les ander
les_ander at yahoo.com
Tue May 7 14:50:52 EDT 2002
Hi,
i have a variable length list of numbers.
i would like to print them out with indicies in front as shown below:
List=['a','b','c','d'] ---> 1:a 2:b 3:c 4:d
one obvious solution is that i do
for i in range(List):
print "%s:%s" % (i+1,List[i])
however i have a lot of these and would like it to be faster so i
tried doing this
formatstr=" %s:%s " * len(List)
print formatstr % (range(1,len(List)+1), List)
but it did not work.
is there a way to do this another way?
les
More information about the Python-list
mailing list