I am trying to get the Resident's into a Dictionary with the residents as members of the residence. This way if I search for Bill, it would return There is a Bill located at Res-Condo-2 and Res-Condo-1. The Text file I am reading from looks like:
************
Ohio
************
Res-House-1
Mickey
Minnie
Goofy
Res-Apt-1
Fred
Barnie
Wilma
Res-Condo-2
Bill
************
Ohio
************
Res-House-2
Stan
Francine
Haley
Stve
Res-Condo-1
Bill
I am able to read the file in and create a list of the Residencies, but I am not able to get the other elements. I also noticed that the list contains the New Line at the end.
list = []
with open('Residencies') as f:
for line in o:
if "Res" in line:
list.append(line)
print(list)
Print Statement output
['Res-House-1\n', 'Res-Apt-1\n', 'Res-Codo-2\n', 'Res-House-2\n', 'Res-Condo-1\n']
How can I get each residence in a dictionary so that I can search which resident belongs to which residence?