SlideShare a Scribd company logo
1 of 1
Download to read offline
12.10 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 0 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: 30: The Simpsons 20:
Gunsmoke; Law & Order 14: Dallas 12: Murder, She Wrote 10: Will & Grace and the file
output_titles.txt should contain:20 Gunsmoke 30 The Simpsons 10 Will & Grace 14 Dallas 20 Law
& Order 12 Murder, She Wrote

More Related Content

More from acetecnagarajan

Overview Universal Computers was one of the worlds largest.pdf
Overview Universal Computers was one of the worlds largest.pdfOverview Universal Computers was one of the worlds largest.pdf
Overview Universal Computers was one of the worlds largest.pdfacetecnagarajan
 
PEDIGREE 4 The Case of the Calico TortoiseShell Cats The.pdf
PEDIGREE 4 The Case of the Calico TortoiseShell Cats The.pdfPEDIGREE 4 The Case of the Calico TortoiseShell Cats The.pdf
PEDIGREE 4 The Case of the Calico TortoiseShell Cats The.pdfacetecnagarajan
 
On January 1 2022 Wildhorse Corporation had the following .pdf
On January 1 2022 Wildhorse Corporation had the following .pdfOn January 1 2022 Wildhorse Corporation had the following .pdf
On January 1 2022 Wildhorse Corporation had the following .pdfacetecnagarajan
 
On March 2 2021 Microsoft released emergency security upda.pdf
On March 2 2021 Microsoft released emergency security upda.pdfOn March 2 2021 Microsoft released emergency security upda.pdf
On March 2 2021 Microsoft released emergency security upda.pdfacetecnagarajan
 
NoteAssignment 2The project is to written by you The use o.pdf
NoteAssignment 2The project is to written by you The use o.pdfNoteAssignment 2The project is to written by you The use o.pdf
NoteAssignment 2The project is to written by you The use o.pdfacetecnagarajan
 
nite III PowerPoint Sunumu Bir toplum hastanesi sistemind.pdf
nite III PowerPoint Sunumu   Bir toplum hastanesi sistemind.pdfnite III PowerPoint Sunumu   Bir toplum hastanesi sistemind.pdf
nite III PowerPoint Sunumu Bir toplum hastanesi sistemind.pdfacetecnagarajan
 
Markus Companys common stock sold for 450 per share at th.pdf
Markus Companys common stock sold for 450 per share at th.pdfMarkus Companys common stock sold for 450 per share at th.pdf
Markus Companys common stock sold for 450 per share at th.pdfacetecnagarajan
 
Merging in the United States in recent years Has become an .pdf
Merging in the United States in recent years Has become an .pdfMerging in the United States in recent years Has become an .pdf
Merging in the United States in recent years Has become an .pdfacetecnagarajan
 
Navarros IntraCompany HedgingNavarro was a USbased mul.pdf
Navarros IntraCompany HedgingNavarro was a USbased mul.pdfNavarros IntraCompany HedgingNavarro was a USbased mul.pdf
Navarros IntraCompany HedgingNavarro was a USbased mul.pdfacetecnagarajan
 
Information he has access to He can simulate two independen.pdf
Information he has access to He can simulate two independen.pdfInformation he has access to He can simulate two independen.pdf
Information he has access to He can simulate two independen.pdfacetecnagarajan
 
1 What is the shape of the pyramid obtained from the census.pdf
1 What is the shape of the pyramid obtained from the census.pdf1 What is the shape of the pyramid obtained from the census.pdf
1 What is the shape of the pyramid obtained from the census.pdfacetecnagarajan
 
1 The Z score is 15 The values of X1X2X3X4 and X5 are.pdf
1 The Z score is 15  The values of X1X2X3X4 and X5 are.pdf1 The Z score is 15  The values of X1X2X3X4 and X5 are.pdf
1 The Z score is 15 The values of X1X2X3X4 and X5 are.pdfacetecnagarajan
 
In the mini lecture The Power of the United States we di.pdf
In the mini lecture The Power of the United States we di.pdfIn the mini lecture The Power of the United States we di.pdf
In the mini lecture The Power of the United States we di.pdfacetecnagarajan
 
HELP PLEASE Event handlers are often called event listeners.pdf
HELP PLEASE  Event handlers are often called event listeners.pdfHELP PLEASE  Event handlers are often called event listeners.pdf
HELP PLEASE Event handlers are often called event listeners.pdfacetecnagarajan
 
1 Anna romanlarnda mkemmel ve ilgi ekici bir kelime daar.pdf
1 Anna romanlarnda mkemmel ve ilgi ekici bir kelime daar.pdf1 Anna romanlarnda mkemmel ve ilgi ekici bir kelime daar.pdf
1 Anna romanlarnda mkemmel ve ilgi ekici bir kelime daar.pdfacetecnagarajan
 

More from acetecnagarajan (15)

Overview Universal Computers was one of the worlds largest.pdf
Overview Universal Computers was one of the worlds largest.pdfOverview Universal Computers was one of the worlds largest.pdf
Overview Universal Computers was one of the worlds largest.pdf
 
PEDIGREE 4 The Case of the Calico TortoiseShell Cats The.pdf
PEDIGREE 4 The Case of the Calico TortoiseShell Cats The.pdfPEDIGREE 4 The Case of the Calico TortoiseShell Cats The.pdf
PEDIGREE 4 The Case of the Calico TortoiseShell Cats The.pdf
 
On January 1 2022 Wildhorse Corporation had the following .pdf
On January 1 2022 Wildhorse Corporation had the following .pdfOn January 1 2022 Wildhorse Corporation had the following .pdf
On January 1 2022 Wildhorse Corporation had the following .pdf
 
On March 2 2021 Microsoft released emergency security upda.pdf
On March 2 2021 Microsoft released emergency security upda.pdfOn March 2 2021 Microsoft released emergency security upda.pdf
On March 2 2021 Microsoft released emergency security upda.pdf
 
NoteAssignment 2The project is to written by you The use o.pdf
NoteAssignment 2The project is to written by you The use o.pdfNoteAssignment 2The project is to written by you The use o.pdf
NoteAssignment 2The project is to written by you The use o.pdf
 
nite III PowerPoint Sunumu Bir toplum hastanesi sistemind.pdf
nite III PowerPoint Sunumu   Bir toplum hastanesi sistemind.pdfnite III PowerPoint Sunumu   Bir toplum hastanesi sistemind.pdf
nite III PowerPoint Sunumu Bir toplum hastanesi sistemind.pdf
 
Markus Companys common stock sold for 450 per share at th.pdf
Markus Companys common stock sold for 450 per share at th.pdfMarkus Companys common stock sold for 450 per share at th.pdf
Markus Companys common stock sold for 450 per share at th.pdf
 
Merging in the United States in recent years Has become an .pdf
Merging in the United States in recent years Has become an .pdfMerging in the United States in recent years Has become an .pdf
Merging in the United States in recent years Has become an .pdf
 
Navarros IntraCompany HedgingNavarro was a USbased mul.pdf
Navarros IntraCompany HedgingNavarro was a USbased mul.pdfNavarros IntraCompany HedgingNavarro was a USbased mul.pdf
Navarros IntraCompany HedgingNavarro was a USbased mul.pdf
 
Information he has access to He can simulate two independen.pdf
Information he has access to He can simulate two independen.pdfInformation he has access to He can simulate two independen.pdf
Information he has access to He can simulate two independen.pdf
 
1 What is the shape of the pyramid obtained from the census.pdf
1 What is the shape of the pyramid obtained from the census.pdf1 What is the shape of the pyramid obtained from the census.pdf
1 What is the shape of the pyramid obtained from the census.pdf
 
1 The Z score is 15 The values of X1X2X3X4 and X5 are.pdf
1 The Z score is 15  The values of X1X2X3X4 and X5 are.pdf1 The Z score is 15  The values of X1X2X3X4 and X5 are.pdf
1 The Z score is 15 The values of X1X2X3X4 and X5 are.pdf
 
In the mini lecture The Power of the United States we di.pdf
In the mini lecture The Power of the United States we di.pdfIn the mini lecture The Power of the United States we di.pdf
In the mini lecture The Power of the United States we di.pdf
 
HELP PLEASE Event handlers are often called event listeners.pdf
HELP PLEASE  Event handlers are often called event listeners.pdfHELP PLEASE  Event handlers are often called event listeners.pdf
HELP PLEASE Event handlers are often called event listeners.pdf
 
1 Anna romanlarnda mkemmel ve ilgi ekici bir kelime daar.pdf
1 Anna romanlarnda mkemmel ve ilgi ekici bir kelime daar.pdf1 Anna romanlarnda mkemmel ve ilgi ekici bir kelime daar.pdf
1 Anna romanlarnda mkemmel ve ilgi ekici bir kelime daar.pdf
 

Recently uploaded

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 

Recently uploaded (20)

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 

1210 LAB Sorting TV Shows dictionaries and lists Write a.pdf

  • 1. 12.10 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 0 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: 30: The Simpsons 20: Gunsmoke; Law & Order 14: Dallas 12: Murder, She Wrote 10: Will & Grace and the file output_titles.txt should contain:20 Gunsmoke 30 The Simpsons 10 Will & Grace 14 Dallas 20 Law & Order 12 Murder, She Wrote