回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我正在学习<code>gensim</code>教程,遇到了一些我不理解的东西。<code>texts</code>是字符串的嵌套列表:</p>
<pre><code>In [37]: texts
Out[37]:
[['human', 'machine', 'interface', 'lab', 'abc', 'computer', 'applications'],
['survey', 'user', 'opinion', 'computer', 'system', 'response', 'time'],
['eps', 'user', 'interface', 'management', 'system'],
['system', 'human', 'system', 'engineering', 'testing', 'eps'],
['relation', 'user', 'perceived', 'response', 'time', 'error', 'measurement'],
['generation', 'random', 'binary', 'unordered', 'trees'],
['intersection', 'graph', 'paths', 'trees'],
['graph', 'minors', 'iv', 'widths', 'trees', 'well', 'quasi', 'ordering'],
['graph', 'minors', 'survey']]
</code></pre>
<p>并且<code>sum(texts,[])</code>给出:</p>
^{pr2}$
<p>这个列表又多了几行,但为了节省空间,我省略了其余的行。我有两个问题:</p>
<p>1)为什么<code>sum(texts,[])</code>会产生这样的结果(即压平嵌套列表)?</p>
<p>2)为什么输出显示奇怪-每行一个元素?这个输出有什么特别的地方吗(…或者我怀疑可能是我的iPython行为异常)。请确认您是否也看到了这个。</p>