Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CODE IS NOT WORKING IN PYTHON 13.9 LAB: Sorting TV Shows (dictionaries and lists) Write a program that first reads in the name of an

CODE IS NOT WORKING

IN PYTHON

image text in transcribedimage text in transcribedimage text in transcribed

13.9 LAB: Sorting TV Shows (dictionaries and lists) Write a program that first reads in the name of an input file and then reads the input file using the file.readlines() method. The input file contains an unsorted list of number of seasons followed by the corresponding TV show. Your program should put the contents of the input file into a dictionary where the number of seasons are the keys, and a list of TV shows are the values (since multiple shows could have the same number of seasons). Sort the dictionary by key (greatest to least) and output the results to a file named output_keys.txt. Separate multiple TV shows associated with the same key with a semicolon (;), ordering by appearance in the input file. Next, sort the dictionary by values (in reverse alphabetical order), and output the results to a file named output_titles.txt. Ex: If the input is: file1.txt and the contents of file1.txt are: 20 Gunsmoke 30 The Simpsons 10 Will \& Grace 14 Dallas 20 Law \& Order 12 Murder, She Wrote the file output_keys.txt should contain: 10: Will \& Grace 12: Murder, She Wrote 14: Dallas 20: Gunsmoke; Law \& Order 30: The Simpsons and the file output_titles.txt should contain: Dallas Gunsmoke Law \& Order Murder, She Wrote The Simpsons will \& Grace 30: The Simpsons 20: Gunsmoke; Law \& Order; Law \& Order: Special Victims Unit 15: ER

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

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions