-1

For example I have this tuple:

(('Samsung J1',), ('Cloudfone Thrill Boost',))

I want to convert it to a string so it will look like this:

Samsung J1
Cloudfone Thrill Boost

I tried doing:

''.join(variablenamefortuple) 

and it did not work just then I realized that it is a list of tuples so I tried mykhal's answer here: Python - convert list of tuples to string

But the strip function only removes from the ends so the output will be like this:

'Samsung J1',), ('Cloudfone Thrill Boost',

How do I remove the extra parentheses as well as the commas and quotation marks? Thanks:)

2
  • print('\n'.join([k[0] for k in s])) Commented Sep 6, 2018 at 2:15
  • 1
    oh ok thanks man:) Commented Sep 6, 2018 at 2:20

1 Answer 1

0

You can do it like this (a small variation on @RafaelC comment):

s = (('Samsung J1',), ('Cloudfone Thrill Boost',))
print('\n'.join([k for k, in s]))

Output

Samsung J1
Cloudfone Thrill Boost
Sign up to request clarification or add additional context in comments.

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.