How do I turn a list of lists of words into a sentence string?

It is a list of strings. So, you need to chain the list of strings, with chain.from_iterable like this

from itertools import chain
print " ".join(chain.from_iterable(strings))
# obytay ikeslay ishay artway

It will be efficient if we first convert the chained iterable to a list, like this

print " ".join(list(chain.from_iterable(strings)))

You have a list in a list so its not working the way you think it should. Your attempt however was absolutely right. Do it as follows:

' '.join(word[0] for word in word_list)

where word_list is your list shown above.

>>> word_list = [['obytay'], ['ikeslay'], ['ishay'], ['artway']]
>>> print ' '.join(word[0] for word in word_list)
obytay ikeslay ishay artway

Tobey likes his wart

Tags:

Python