高效的方式非常大名單對名單進行異或運算,使得XOR其旋轉
如:
#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]
爲列表的大小是非常大的,有沒有解決任何有效的方式。
這是迄今爲止我所做的。
#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)
除了構建並返回新列表的列表片段之外,您應該使用'itertools.islice'來提高空間效率。 –
@ juanpa.arrivillaga完成。 – Nf4r