Question
Need help with Zybooks 4.9.1: LAB: Sorting TV Shows (dictionaries and lists) I keep getting this: Your file content 10: Will & Grace 12: Murder,
Need help with Zybooks 4.9.1: LAB: Sorting TV Shows (dictionaries and lists) I keep getting this: Your file content 10: Will & Grace 12: Murder, She Wrote 14: Dallas 20: Gunsmoke; Law & Order 30: The Simpsons I am suppose to get this: Expected file content 30: The Simpsons 20: Gunsmoke; Law & Order 14: Dallas 12: Murder, She Wrote 10: Will & Grace This is my code: inputFilename = input("Enter filename: ") keysFilename = 'output_keys.txt' titlesFilename = 'output_titles.txt' shows = {} with open(inputFilename) as inputFile: showData = inputFile.readlines() record_count = int(len(showData) / 2) for i in range(record_count): seasons = int(showData[2 * i].strip()) showName = showData[2 * i + 1].strip() if seasons in shows: shows[seasons].append(showName) else: shows[seasons] = [showName] with open(keysFilename, 'w') as keysFile: for season in sorted(shows): keysFile.write(str(season) + ': ') keysFile.write('; '.join(shows[season]) + ' ') with open(titlesFilename, 'w') as titlesFile: for show_list in sorted(shows.values()): for show in show_list: titlesFile.write(show + " ")
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