擅长:python、mysql、java
<h2>解决方案</h2>
<p>即使<code>longList</code>中的元素数不是<code>shortList</code>的精确倍数,下面的代码也可以工作。它也不需要任何<code>import</code>语句。你知道吗</p>
<pre class="lang-py prettyprint-override"><code>longList = [10, 10, 10, 10, 10, 10, 10, 10, 10,]
shortList = [1, 2, 3]
container = list()
n = len(longList)%len(shortList)
m = int(len(longList)/len(shortList))
for _ in range(m):
container += shortList.copy()
if n>0:
container += shortList[:n]
[e*f for e,f in zip(container, longList)]
</code></pre>
<p><strong>输出</strong>:</p>
<pre><code>[10, 20, 30, 10, 20, 30, 10, 20, 30]
</code></pre>