回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我正在尝试筛选字符串列表中等于1个字符或2个字符的单词。这是我的样本数据-</p>
<pre><code>l = ['new vaccine tech long term testing',
'concerned past negative effects vaccines flu shot b',
'standard initial screening tb never tb chest x ray']
</code></pre>
<p>我试着写这个逻辑,但不知怎么的,输出结果是一个单词列表,而不是句子列表</p>
<pre><code>cleaner = [ ''.join(word) for each in l for word in each.split() if len(word) > 2 ]
cleaner
['new',
'vaccine',
'tech',
'long',
'term',
'testing',
'concerned',
'past',
'negative',
'effects',
'vaccines',
'flu',
'shot',
'standard',
'initial',
'screening',
'never',
'chest',
'ray']
</code></pre>
<p>如何使其输出如下</p>
<pre><code>output = ['new vaccine tech long term testing',
'concerned past negative effects vaccines flu shot',
'standard initial screening never chest ray']
</code></pre>