Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

Students also viewed these Databases questions

Question

List and describe each of the components in the data hierarchy.

Answered: 1 week ago

Question

KEY QUESTION Refer to columns 1 and 6 in the table for question

Answered: 1 week ago