0

I'm searching a simple method for converting a list of strings (e.g. ['test 1', 'test 2' , 'test 3'] ) into a string whereby the list of objects doesn't have some quotation mark. That means in our example ('[test 1, test 2, test 3]'). My first approach was:

import json
A = ['test 1', 'test 2' , 'test 3']
test = json.dumps(A).replace('"', '')

Is their a more general way without that replace statement at the background? Cause my problem with that is, that e.g.

A = ['test 1', 'test 2' , 'test 3"AA"']

results in the string:

   '[test 1, test 2, test 3\AA\]'

and not the desired string:

'[test 1, test 2, test 3"AA"]'

2 Answers 2

4

Try f-strings:

>>> print(f"'[{', '.join(A)}]'")
'[test 1, test 2, test 3"AA"]'

# OR

>>> print(f"[{', '.join(A)}]")
[test 1, test 2, test 3"AA"]
Sign up to request clarification or add additional context in comments.

Comments

2

A simple way you could try would be

A = ['test 1', 'test 2' , 'test 3"AA"'] #your list
print (*A, sep =', ')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.