Stringify a list

Simon Brunning SBrunning at trisystems.co.uk
Wed May 16 05:17:10 EDT 2001


> I have a list object that contains card values (i.e. 2-10, J, Q, K, A),
> but I can't seem to print the list in such a way that it doesn't appear as
> follows:
> 
> 	[2, 6, 'A', 8, 'J']
> 
> I don't mind the commas, but how do I remove the quotes and brackets
> without going through contortions?
 
If every item in you list is a string, you can just use:

' '.join(mylist)

In you example, though, some if the items appear to be integers - so try
this:

' '.join([str(item) for item in mylist])

Cheers,
Simon Brunning
TriSystems Ltd.
sbrunning at trisystems.co.uk




-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.




More information about the Python-list mailing list