printing list

Raymond L. Buvel levub137 at wi.rr.com
Sun May 7 12:35:41 EDT 2006


compboy wrote:
> How do you print elements of the list in one line?
> 
> alist = [1, 2, 5, 10, 15]
> 
> so it will be like this:
> 1, 2, 5, 10, 15
> 
> because if I use this code
> 
> for i in alist:
>     print i
> 
> the result would be like this
> 
> 1
> 2
> 5
> 10
> 15
> 
> Thanks.
> 

There are a number of ways to do it but if you want a one-liner:

print repr(alist)[1:-1]

will meet your spec.



More information about the Python-list mailing list