Swap every Nth element of two lists
<p>I have two lists as:</p>

<pre><code>l1 = [1, 2, 3, 4, 5, 6]
l2 = ['a', 'b', 'c', 'd', 'e', 'f']
</code></pre>

<p>I need to swap every <code>N</code>th element of these lists. For example if <code>N=3</code>, desired result is:</p>

<pre><code>l1 = [1, 2, 'c', 4, 5, 'f']
l2 = ['a', 'b', 3, 'd', 'e', 6]
</code></pre>

<p>I can do it via <code>for</code> loop and swap every <code>N</code>th element as:</p>

<pre><code>&gt;&gt;&gt; for i in range(2,len(l1),3):
...     l1[i], l2[i] = l2[i], l1[i]
... 
&gt;&gt;&gt; l1, l2
([1, 2, 'c', 4, 5, 'f'], ['a', 'b', 3, 'd', 'e', 6])
</code></pre>

<p>I want to know whether there is much more efficient way to achieve it. May be without <code>for</code> loop.</p>

<p>Note: Length of both lists will be same.</p>

<p>We can achieve that via <code>list slicing</code> as:</p>

<pre><code>&gt;&gt;&gt; l1[2::3], l2[2::3] = l2[2::3], l1[2::3]
&gt;&gt;&gt; l1, l2
([1, 2, 'c', 4, 5, 'f'], ['a', 'b', 3, 'd', 'e', 6])
</code></pre>

python list swap