リストにデータがあります:印刷機能を与えるとうまく印刷されるls1
[5, 2, 7, 4, 3, 9, 8, 6, 10]
ただし、これを試すとエラーが発生します。
P81=[]
P81.append(ls1[5])
コードに何か問題がありますか?参考までに全文を載せておきます。このコードは、10 個の要素リストを受け取り、いくつかの順列とシフトを実行する単なるキー生成関数です。leftShift は、リストに対してシフト操作を実行するだけの関数です。
def keyGen(key):
import numpy
#3 5 2 7 4 10 1 9 8 6
P10=[]
P10.append(key[2])
P10.append(key[4])
P10.append(key[1])
P10.append(key[6])
P10.append(key[3])
P10.append(key[9])
P10.append(key[8])
P10.append(key[7])
P10.append(key[5])
#Now, P10 contains the keys after initial permutation
#Take 2 halves and perform left shift
ls1a=leftShift(P10[0:5])
ls1b=leftShift(P10[5:10])
ls1=ls1a+ls1b
P81=[]
#6 3 7 4 8 5 10 9
print ls1
P81.append(ls1[5])
P81.append(ls1[2])
P81.append(ls1[6])
P81.append(ls1[3])
P81.append(ls1[7])
P81.append(ls1[4])
P81.append(ls1[9])
P81.append(ls1[8])
#For the second set of keys perform the second shift
ls2a=leftShift(ls1a)
ls2b=leftShift(ls1b)
ls2=ls2a+ls2b
P82=[]
P82.append(ls2[5])
P82.append(ls2[2])
P82.append(ls2[6])
P82.append(ls2[3])
P82.append(ls2[7])
P82.append(ls2[4])
P82.append(ls2[9])
P82.append(ls2[8])
return([P81,P82])