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
icon
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.
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
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Parallel Processing
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education