XOR very big List with its rotation
<p>Efficient way to XOR on list such that,</p>

<p>eg:</p>

<pre><code>#here a,b,c,d are integers
L = [a,b,c,d]
N = [b,c,d,a] #right rotation of list L

Newlist = enter code here[a^b, b^c, c ^d ,d^a]
</code></pre>

<p>as size of list is very large, is there any efficient way to solve.</p>

<p>this is so far what i have done.</p>

<pre><code>#right rotation of list
def shift(seq, n):
    n = n % len(seq)
    return seq[n:] + seq[:n]

L = [6,7,1,3]
N = shift(L,1)
new = []
for i,j in zip(L,N):
    new.append(i^j)
print(new)
</code></pre>

<p>You can try to check this:</p>

<pre><code>from collections import deque

L = [6, 7, 1, 3]
L2 = deque(L)
L2.rotate(-1) # rotate to left
result = [i ^ j for i, j in zip(L, L2)]
</code></pre>

<p>This might be at least slightly faster.</p>

<p>Other solution would be to check this possibility:</p>

<pre><code>from itertools import islice
L = [6, 7, 1, 3]
# This will add all the XoRs except for the last pair (6, 3)
result = [i ^ j for i, j in zip(L, islice(L, 1, len(L))] 
# adding the last XOR
result.append(L[0] ^ [L-1])
print(result)
[1, 6, 2, 5]
</code></pre>

python xor