Возможно, я пытаюсь работать со структурами данных, которые не соответствуют моим потребностям, однако ... учитывая это:
import itertools
listOfFileData = [['[', 'Emma', 'by', 'Jane', 'Austen'] ,['[', 'Persuasion', 'by', 'Jane', 'Austen'] ,['[', 'Sense', 'and', 'Sensibility', 'by'] ,
['[', 'The', 'King', 'James', 'Bible'] ,['[', 'Poems', 'by', 'William', 'Blake'] ,['[', 'Stories', 'to', 'Tell', 'to'] ,
['[', 'The', 'Adventures', 'of', 'Buster'] ,['[', 'Alice', "'", 's', 'Adventures'] ,
['[', 'The', 'Ball', 'and', 'The'] ,['[', 'The', 'Wisdom', 'of', 'Father'] ,['[', 'The', 'Man', 'Who', 'Was'] ,
['[', 'The', 'Parent', "'", 's'] ,['[', 'Moby', 'Dick', 'by', 'Herman'] ,['[', 'Paradise', 'Lost', 'by', 'John'] ,
['[', 'The', 'Tragedie', 'of', 'Julius'] ,['[', 'The', 'Tragedie', 'of', 'Hamlet'] ,['[', 'The', 'Tragedie', 'of', 'Macbeth'] ,
['[', 'Leaves', 'of', 'Grass', 'by'] ]
#print(len(listOfFileData)) # should show 18 files, each is a list of tokens.
filesDataPairsList = list(itertools.combinations(listOfFileData, 2)) # requires itertools library file(s)
filesDataPairsListTesting = []
for i in range(2,19,2): # 2,4,6,8,...18
combinationOfPairsList = list(itertools.combinations(listOfFileData[:i], 2)) # make a list, of increasingly sized pairs
filesDataPairsListTesting.append(combinationOfPairsList)
#print(len(filesDataPairsListTesting)) # should have 9 lists
#print(len(filesDataPairsListTesting[8])) # should have 153 pairs
Как мне добраться до каждой пары в цикле?Я работал над чем-то вроде следующего.Но я туда не доберусь.
for permutations in filesDataPairsListTesting:
# print(len(permutations)) # if uncommented should read, 1,6,15,28....153
for numOfPairs in range(len(permutations)):
for pair in permutations:
permutations[0]
permutations[1]
Я хотел бы получить доступ к каждой паре списков [[], []], чтобы иметь возможность обрабатывать каждый из документов из каждой пары в блоке for.
То есть с элементом 0 в моем списке filesDataPairsListTesting.Я мог бы легко добраться до каждого предмета, как
permutations[0]
permutations[1]
Но у 2-го элемента тогда есть 6 пар ...?Поэтому я должен пройти элемент 1 6 раз (как?), Чтобы я мог перейти к перестановкам [0], перестановкам [1].Это та часть, которая бросает меня.