Question
I'm having a problem getting this zybooks lab to work properly, at this point I think I am just making it worse, please help me
I'm having a problem getting this zybooks lab to work properly, at this point I think I am just making it worse, please help me debug this
import txt
def readFile(filename): # define filename dict = {} # create dictionary for file - key: num seasons, value: list of shows shows = [] #create list for shows with open(filename, 'r') as file: # open file use 'r' to read file lines = file.readlines() # define lines for strings created by readlines for index in range(0, len(lines), 2): # create loop for incrementing of 2 show = lines[index+1] # reads in value as show shows.append(show) # adds shows to shows list if seasons in dict: # check for season in dictionary dict[seasons].append(show) # adds new elements, value to show else: dict[seasons] = [show] # add show to show list with open('output_keys.txt', 'w') as key_file: # open write file for output for key in sorted(dict.keys()): # creates loop to sort keys in dictionary key_file.write(key + ': ' + ';'.join(key)) # join key for seasons add :, ; and join shows list print(key + ': ' + ';'.join(key)) # print output with open('output_titles.txt', 'w') as value_file: #open write file for output for value in sorted(shows): # creates loop to sort shows list value_file.write(value ) # writes out values of list print(value ) #print output
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started