回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我有以下包含列表和字符串的<code>lista</code>:</p>
<pre><code>['IBERDROLA', 'ACCOR\xa0SA', ['ADMIRAL'], ['ADECCO', 'IAG']]
</code></pre>
<p>我想用这个输出使它成为<code>flat_list</code>:</p>
<pre><code>['IBERDROLA', 'ACCOR\xa0SA', 'ADMIRAL', 'ADECCO', 'IAG']
</code></pre>
<p>可能我没有使用正确的关键字来找到想要的答案,买我只找到
<a href="https://stackoverflow.com/questions/952914/making-a-flat-list-out-of-list-of-lists-in-python">Making a flat list out of list of lists in Python</a>
(没有<code>str</code>类似的地雷)转换成<code>flat_list</code>,输出如下:</p>
<pre><code>flat_list = [item for sublist in lista for item in sublist]
['I', 'B', 'E', 'R', 'D', 'R', 'O', 'L', 'A', 'A', 'C', 'C', 'O', 'R', '\xa0', 'S', 'A', 'ADMIRAL', 'ADECCO', 'IAG']
</code></pre>