擅长:python、mysql、java
<p>下面是我的解决方案:使用列表理解创建第四个列表,我将其命名为<code>mixed</code>。你知道吗</p>
<pre><code>numbers = [1, 2, 3, 4, 5, 6]
letters = ['a', 'b', 'a', 'b', 'c', 'c']
states = [False, False, False, False, False, False]
choice1 = 0
choice2 = 2
if letters[choice1] == letters[choice2]:
states[choice1] = True
states[choice2] = True
mixed = [letter if use_letter else number
for number, letter, use_letter in zip(numbers, letters, states)]
print numbers
print letters
print states
print mixed
</code></pre>
<p>输出:</p>
<pre><code>[1, 2, 3, 4, 5, 6]
['a', 'b', 'a', 'b', 'c', 'c']
[True, False, True, False, False, False]
['a', 2, 'a', 4, 5, 6]
</code></pre>
<p>注意,在代码中,我压缩了三个列表,并使用<code>states</code>列表中的元素从其他两个列表中选取元素。另外,我将<code>state</code>(单数)重命名为<code>states</code>(复数),以与其他列表的命名约定保持一致。你知道吗</p>