[Q] A better way to print?
Alex Martelli
aleax at aleax.it
Sat Feb 22 15:07:30 EST 2003
Eric Gorr wrote:
> I have some print code that looks like:
>
> for i in range(N-1):
> print W[i],
> sys.stdout.softspace = 0
> print '-',
> sys.stdout.softspace = 0
>
> print W[-1]
>
> and this outputs things of the form:
>
> 1-0-1-0-0-0
>
> is there a better method?
print '-'.join( [str(witem) for witem in W] )
would seem to be one of the best solutions. A variant:
print '-'.join( map(str, W) )
Alex
More information about the Python-list
mailing list