擅长:python、mysql、java
<p>如果更改<code>short_list</code>没有问题,可以使用<a href="https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions" rel="nofollow noreferrer">list comprehension</a>尝试以下操作:</p>
<pre><code>[short_list.pop(0) if i == '1' else 99 for i in long_list]
</code></pre>
<p><strong>输出:</strong></p>
<pre><code>>>> long_list = ['0', '1', '0', '1', '0', '0', '0', '1', '1', '0']
>>> short_list = [8, 7, 6, 5]
>>>
>>> [short_list.pop(0) if i == '1' else 99 for i in long_list]
[99, 8, 99, 7, 99, 99, 99, 6, 5, 99]
</code></pre>