So I want to find the number of times certain characters’ names appear in my text file which therefore indicates who have the most speech, this is my code:
dict_4 = {}
characters_1 = ('(SATURNINUS','BASSIANUS','TITUS ANDRONICUS','MARCUS ANDRONICUS','LUCIUS','QUINTUS','MUTIUS','Young LUCIUS','PUBLIUS','SEMPRONIUS','CAIUS','VALENTINE')
characters_2 = ('AEMILIUS','ALARBUS','DEMETRIUS','CHIRON','AARON','Captain','Tribune','Messenger','Clown')
characters_3 = ('Romans','Goths','TAMORA','LAVINIA','A Nurse','Senators, Tribunes, Officers, Soldiers, anAttendants.')
characters = characters_1 + characters_2 + characters_3
#Here I have made a list of all my characters
opening = open('file2.txt','r').read()
for word in opening and word in characters:
if word in dict_4:
dict_4[word] +=1
else:
dict_4[word] = 1
print(dict_4)
However I get the error that TypeError: 'bool' object is not iterable
on the for word in opening and word in characters:
line.
Before, it wasn’t creating a dictionary. Is there anyone who could offer some advice please?