I have gone back through all of the coursework on generator functions and expressions. I have looked through all of the previous topics posted and have not seen this particular issue brought up.
I am on Task #4. I can generate all the names of the guests over the age of 21, including Jane, except for Dixie, aged 46 and Rose, aged 65. Dixie is in the initial 10 guests and Rose is in the guest list after Jane is added.
I have included a link to the project below, as well as my code. I could almost understand if Jane was missing (and that seems the more prevalent issue), but I am stumped with why these 2 names, from before and after the .send was executed, are not in the generated list.
guests = {}
def read_guestlist(file_name):
text_file = open(file_name,'r')
while True:
line_data = text_file.readline().strip().split(",")
guest = yield line_data
if guest is not None:
line_data = guest.split(',')
name = line_data[0]
age = int(line_data[1])
guests[name] = age
n = yield line_data
name = line_data[0]
age = int(line_data[1])
guests[name] = age
if len(line_data) < 2:
# If no more lines, close file
text_file.close()
break
guestlist = read_guestlist('guest_list.txt')
for guest in range(0, 10):
print(next(guestlist))
print(guestlist.send('Jane,35'))
for guest in range(10, 14):
print(next(guestlist))
print('\n')
legal_age_guests = (name for name, age in guests.items() if age > 20)
for names in legal_age_guests:
print(names)