printing list

Mel Wilson mwilson-to at sympatico.ca
Sun May 7 18:16:22 EDT 2006


Tim Chase wrote:
> 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
> 
> 
>  >>> print ', '.join(alist)
> 1, 2, 5, 10, 15

???

Python 2.4.2 (#1, Jan 23 2006, 21:24:54)
[GCC 3.3.4] on linux2
Type "help", "copyright", "credits" or "license" for more 
information.
 >>> a=[1,2,3,4,5]
 >>> print ', '.join (a)
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
TypeError: sequence item 0: expected string, int found
 >>> print ', '.join ('%d'%x for x in a)
1, 2, 3, 4, 5



More information about the Python-list mailing list