回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>在python中创建一个新的单词列表,并在其中创建一个新的单词列表。我的意思是列表应该在文本文件中的每一个双空格中创建存在项。在</p>
<p>这是我的职责:</p>
<pre><code>def tokenize(document):
file = open("document.txt","r+").read()
print re.findall(r'\w+', file)
</code></pre>
<p>输入文本文件包含如下字符串:</p>
^{pr2}$
<p>注意:典狱长后面有两个空格?在他之前</p>
<p>我的函数给我这样的输出</p>
<pre class="lang-none prettyprint-override"><code>['what','s','did','the','little','boy','tell','the','game','warden','His','dad','was','in','the','kitchen','poaching','eggs']
</code></pre>
<p>期望输出:</p>
<pre class="lang-none prettyprint-override"><code>[['what','s','did','the','little','boy','tell','the','game','warden'],
['His','dad','was','in','the','kitchen','poaching','eggs']]
</code></pre>