How to reconstruct a list with punctuation into a sentence? In python 3.5
<p>I have a list e.g. <code>['hello',', ','how','are','you','?']</code> and i want it to become <code>"hello, how are you?"</code>
Is there anyway at doing this?</p>

<p>I should also note that i am opening this from a text document, using the code:</p>

<pre><code>    with gzip.open('task3.txt.gz', 'r+') as f:
    reconstruct = f.readline()
    reconstruct2 = f.readline()
    reconstruct3 = f.readline()
    reconstruct4 = f.readline()
    f.close()
</code></pre>

<p>So my lists come out as <code>b'["hello", ",", "how", "are", "you", "?"]\n'</code> could this be linked to the fact i saved them with new lines?</p>

<p>You can actually properly <em>detokenize</em> the list of tokens back into a sentence with an <a href="https://github.com/nltk/nltk/pull/1282" rel="nofollow"><code>nltk</code>'s <code>moses</code> detokenizer</a> (available in the <code>nltk</code> trunk at the moment - has not been released yet):</p>

<pre><code>In [1]: from nltk.tokenize.moses import MosesDetokenizer

In [2]: l = ['hello', ', ', 'how', 'are', 'you', '?']

In [3]: detokenizer = MosesDetokenizer()

In [4]: detokenizer.detokenize(l, return_str=True)
Out[4]: u'hello, how are you?'
</code></pre>

python python-3.x