4.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.readlines0 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 (least to greatest) and output the results to a file named outputkeys.txt, separating multiple TV shows associated with the same key with a semicolon (). Next, sort the dictionary by values (alphabetical order). and output the results to a file named outputLtitles.txt Ex If the input is: filel.txt and the contents of file1 txt are 07 Gunsmoke The Simpsons Will & Grace Dallas Hapzo MeT Murder
4.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.readlines0 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 (least to greatest) and output the results to a file named outputkeys.txt, separating multiple TV shows associated with the same key with a semicolon (). Next, sort the dictionary by values (alphabetical order). and output the results to a file named outputLtitles.txt Ex If the input is: filel.txt and the contents of file1 txt are 07 Gunsmoke The Simpsons Will & Grace Dallas Hapzo MeT Murder
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Having trouble with this lab producing no output
4.9 Lab: Sorting TV shows (dictionaries and lists) in python
![R
&Home
2y Section 5.15-CYB/135: Object-C X
zy Section 4.9 - CYB/135: Object-Or X
Content
A learn.zybooks.com/zybook/CYB_135_55317605/chapter/4/section/9
= zyBookS My library > CYB/135: Object-Oriented Security Scripting home > 4.9: LAB: Sorting TV Shows (dictionaries and lists)
E zyBooks catalog
2 Help/FAQ 8 Ric-
LAB
4.9.1: LAB: Sorting TV Shows (dictionaries and lists)
0/10
ACTIVITY
Downloadable files
filel.txt
Download
main.py
Load default template
1 def readFile(filename):
{} = 1PP
lines = infile.readlines()
for index in range (0, len(lines) -1, 2):
if lines[index].strip()==' ':
continue
2
with open(filename, 'r') as infile:
4.
count = int(lines[index].strip()
name = lines[index + 1].strip()
if count in dict.keys():
dict[count].append (name)
else:
8.
6.
11
12
dict[count] = [name]
print (count,name)
13
14
15
return dict
16
17 def output keys(dict, filename):
Run your program as often as you'd like. before submitting for grading Below type any needed
input values in the first box, then click Run program and observe the program's output in the
Submit mode
opow dojanag
second box.
Enter program input (optional)
Gunsmoke
91
23
esnod
因
VOUOA
8
bockspace
5.
H
7.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F2f8ed8ef-22db-479b-97c2-724e226c1280%2F6a04b7ab-cd25-4048-9755-254e66b5a92b%2Fulkw4cq_processed.jpeg&w=3840&q=75)
Transcribed Image Text:R
&Home
2y Section 5.15-CYB/135: Object-C X
zy Section 4.9 - CYB/135: Object-Or X
Content
A learn.zybooks.com/zybook/CYB_135_55317605/chapter/4/section/9
= zyBookS My library > CYB/135: Object-Oriented Security Scripting home > 4.9: LAB: Sorting TV Shows (dictionaries and lists)
E zyBooks catalog
2 Help/FAQ 8 Ric-
LAB
4.9.1: LAB: Sorting TV Shows (dictionaries and lists)
0/10
ACTIVITY
Downloadable files
filel.txt
Download
main.py
Load default template
1 def readFile(filename):
{} = 1PP
lines = infile.readlines()
for index in range (0, len(lines) -1, 2):
if lines[index].strip()==' ':
continue
2
with open(filename, 'r') as infile:
4.
count = int(lines[index].strip()
name = lines[index + 1].strip()
if count in dict.keys():
dict[count].append (name)
else:
8.
6.
11
12
dict[count] = [name]
print (count,name)
13
14
15
return dict
16
17 def output keys(dict, filename):
Run your program as often as you'd like. before submitting for grading Below type any needed
input values in the first box, then click Run program and observe the program's output in the
Submit mode
opow dojanag
second box.
Enter program input (optional)
Gunsmoke
91
23
esnod
因
VOUOA
8
bockspace
5.
H
7.
![Home
Content
29 Section 5.15-CYB/135: Object-C X
zy Section 4.9- CYB/135: Object-Or x
A learn.zybooks.com/zybook/CYB_135_55317605/chapter/4/section/9
= zyBooks My library > CYB/135: Object-Oriented Security Scripting home > 4.9: LAB: Sorting TV Shows (dictionaries and lists)
E zyBooks catalog e Help/FAQ 8 Ricky Ortiz -
4.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 (least to greatest) and output the results to a file named output keys.txt separating multiple TV shows
associated with the same key with a semicolon (). Next, sort the dictionary by values (alphabetical order), and output the results to a file
named output titles.txt.
Ex: If the input is:
filel.txt
and the contents of file1 txt are:
Gunsmoke
The Simpsons
Will & Grace
קס]ןeo
Law & Order
12
Murder, She Wrote
906
PAum k
8.
enter
7.
shift &
alt
ctrl
41b](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F2f8ed8ef-22db-479b-97c2-724e226c1280%2F6a04b7ab-cd25-4048-9755-254e66b5a92b%2Fytua0jd_processed.jpeg&w=3840&q=75)
Transcribed Image Text:Home
Content
29 Section 5.15-CYB/135: Object-C X
zy Section 4.9- CYB/135: Object-Or x
A learn.zybooks.com/zybook/CYB_135_55317605/chapter/4/section/9
= zyBooks My library > CYB/135: Object-Oriented Security Scripting home > 4.9: LAB: Sorting TV Shows (dictionaries and lists)
E zyBooks catalog e Help/FAQ 8 Ricky Ortiz -
4.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 (least to greatest) and output the results to a file named output keys.txt separating multiple TV shows
associated with the same key with a semicolon (). Next, sort the dictionary by values (alphabetical order), and output the results to a file
named output titles.txt.
Ex: If the input is:
filel.txt
and the contents of file1 txt are:
Gunsmoke
The Simpsons
Will & Grace
קס]ןeo
Law & Order
12
Murder, She Wrote
906
PAum k
8.
enter
7.
shift &
alt
ctrl
41b
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education