[Q] A better way to print?

Dan Bishop danb_83 at yahoo.com
Sat Feb 22 21:55:36 EST 2003


eRrEiMcOgVoErMrE at cox.net (Eric Gorr) wrote in message news:<1fqsf0w.i3i7qq41g4wN%eRrEiMcOgVoErMrE at cox.net>...
> 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?

The simplest way is

print '-'.join(W)




More information about the Python-list mailing list