1

I am looking for a way to turn this:
[['a','b'],['c','d'],['e','f']]
Into this:
'ab\ncd\nef'
So that when it is printed out it will look like:

ab
cd
ef
1
  • 3
    "\n".join("".join(s) for s in [['a','b'],['c','d'],['e','f']]) Commented Apr 4, 2017 at 18:18

2 Answers 2

3

Try:

list_ = [['a','b'],['c','d'],['e','f']]
'\n'.join([''.join(l) for l in list_])
Sign up to request clarification or add additional context in comments.

1 Comment

Regarding your comment (which seems now deleted): If you want the elements in the sublist be seperated by comma, just replace ''.join(l) by ','.join(l)
1

Here you go for a harder way :

x = [['a','b'],['c','d'],['e','f']]
string = ''
for i in x:
    for e in i:
        string+=e
    string+="\n"

print string

however, "\n".join() also works

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.