Stringify a list

Terry Reedy reedy37 at home.com
Wed May 16 13:14:37 EDT 2001


"Todd A. Jacobs" <nospam at codegnome.org> wrote in message
news:mailman.990003323.2806.python-list at python.org...
> 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?

Other have given you 'build' methods.  A simple 'remove' method:

>>> import string
>>> null = string.maketrans('','')
>>> string.translate("[2, 6, 'A', 8, 'J']", null, "[']")
'2, 6, A, 8, J'






More information about the Python-list mailing list