I have three lists in this program. 'library' contains a large amount of text, 'references' contains a list of words that follow each other in references, and 'possibles' looks at every time that each item in 'references' appear together so it can get the following word.
The program gets the length of 'references' so it knows how many items to check in 'library', but the piece of code that checks if references has 2 items in it returns 'unexpected indention', and I can't figure out why. Even if I remove the indention, it returns the error. If it is not indented, there is an error because it disrupts the rest of the code.
Below is the entire function. The entire program works aside from the indention error.
def possibles_compile():
compile = 'yes'
global temp_possibles
temp_possibles = []
while compile != 'no':
if len(reference) == 1:
for i in range(library_length):
try:
if library[i] == reference[0]:
try:
temp_possibles.append(library[i + 1])
except IndexError:
temp_possibles.append(library[0])
elif len(reference) == 2:
for i in range(library_length):
if library[i] == reference[0]:
try:
if library[i + 1] == reference[1]:
try:
temp_possibles.append(library[i + 2])
except IndexError:
temp_possibles.append(library[0])
except IndexError:
if library[0] == reference[1]:
temp_possibles.append(library[1])
elif len(reference) == 3:
for i in range(library_length):
if library[i] == reference[0]:
try:
library[i + 1] == reference[1]:
except IndexError:
if library[0] == reference[1]:
if library[1] == reference[2]:
temp_possibles.append(library[2])
else:
try:
if library[i + 2] == reference[2]:
try:
temp_possibles.append(library[i + 3])
except IndexError:
temp_possibles.append(library[0])
except IndexError:
if library[0] == reference[2]:
temp_possibles.append(library[1])
elif len(reference) == 4:
for i in range(library_length):
if library[i] == reference[0]:
try:
library [i + 1] == reference[1]:
except IndexError:
if library[0] == reference[1]:
if library[1] == reference[2]:
if library[2] == reference[3]:
temp_possibles.append(library[3])
else:
try:
library[i + 2] == reference[2]:
except IndexError:
if library[0] == reference[2]:
if library[1] == reference[3]:
temp_possibles.append(library[2])
else:
try:
if library[i + 3] == reference[3]:
try:
temp_possibles.append(library[i + 4])
except IndexError:
temp_possibles.append(library[0])
except IndexError:
if library[0] == reference[3]:
temp_possibles.append(library[1])
compile = 'no'
return 'done'