配列内の4つのオブジェクトをランダム化してランダムに選択する場所を探しています。私はその選択されたオブジェクトの元のインデックス番号を取得する必要があります。私はこれをどのようにできるだけ短く書くべきかに関する考え方は何ですか?配列から無作為化項目を選択した後に項目インデックスを見つける方法
arrayRandomSongs = []
arrayChosen = []
trackChosen = ""
def randomizeArray(self):
del self.arrayRandomSongs[:] # wipes array of all contents without making a new one
self.arrayRandomSongs = self.arraySongs[:]
random.shuffle(self.arrayRandomSongs)
def chooseListing(self):
del self.arrayChosen[:] # same here
for i in xrange(4):
self.arrayChosen.append(self.arrayRandomSongs[i])
del self.arrayRandomSongs[0:3]
def chooseTrack(self):
self.trackChosen = random.choice(self.arrayChosen)
あなたは私がtrackChosenオブジェクトのarayChosenインデックス番号を選択したいと思いますが、それはランダム化されていますので、私はそれを行う可能性がどのように表示されていない見ることができるように。
元の元の配列ではなく、arrayChosenのインデックス番号を取得したいのですが、 –