-2

I have a nested list:

encode= [['t','h','i','s'],['i','s'],['a','w','s','o','m','e']]

and I want to convert the nested list above into a string:

"this is awesome"
moopet
  • 6,014
  • 1
  • 29
  • 36
Joyce Hong
  • 19
  • 4

3 Answers3

3

the join in the list comprehension joins the letters into words, then the join outside the list joins the words into a sentence

' '.join([''.join(x) for x in encode])
Kyle Safran
  • 463
  • 3
  • 8
0

Simply:

words = [''.join(word) for word in encode]
sentence = ' '.join(words)
quamrana
  • 37,849
  • 12
  • 53
  • 71
0
l =" ".join(["".join(i) for i in encode])
dejanualex
  • 3,872
  • 6
  • 22
  • 37
  • 2
    The provided answer was flagged for review as a Low Quality Post. This provided answer may be correct, but **it could benefit from an explanation**. Code only answers are not considered "good" answers. Here are some guidelines for [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer). From [review](https://stackoverflow.com/review). – MyNameIsCaleb Oct 01 '19 at 01:55