Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created December 23, 2021 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/06b174759edc84696c70ec4463ed4897 to your computer and use it in GitHub Desktop.
Save codecademydev/06b174759edc84696c70ec4463ed4897 to your computer and use it in GitHub Desktop.
Codecademy export
Tim,22
Tonya,45
Mary,12
Ann,32
Beth,20
Sam,5
Manny,76
Kenton,15
Kenny,27
Dixie,46
Mallory,32
Julian,4
Edward,71
Rose,65
guests = {}
def read_guestlist(file_name):
text_file = open(file_name,'r')
while True:
line_data = text_file.readline().strip().split(",")
if len(line_data) < 2:
# If no more lines, close file
text_file.close()
break
name = line_data[0]
age = int(line_data[1])
guests[name] = age
yield line_data
lst = read_guestlist('guest_list.txt')
for i in range(0, 10):
print(next(lst))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment