1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
zvonat [6]
3 years ago
14

Write a program that first reads in the name of an input file and then reads the input file using the file.readlines() method. T

he 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).
Computers and Technology
1 answer:
irinina [24]3 years ago
3 0

Answer:

def readFile(filename):

   dict = {}

   with open(filename, 'r') as infile:

       lines = infile.readlines()

       for index in range(0, len(lines) - 1, 2):

           if lines[index].strip()=='':continue

           count = int(lines[index].strip())

           name = lines[index + 1].strip()

           if count in dict.keys():

               name_list = dict.get(count)

               name_list.append(name)

               name_list.sort()

           else:

               dict[count] = [name]

           print(count,name)

   return dict

def output_keys(dict, filename):

   with open(filename,'w+') as outfile:

       for key in sorted(dict.keys()):

           outfile.write('{}: {}\n'.format(key,';'.join(dict.get(key))))

           print('{}: {}\n'.format(key,';'.join(dict.get(key))))

def output_titles(dict, filename):

   titles = []

   for title in dict.values():

       titles.extend(title)

   with open(filename,'w+') as outfile:

       for title in sorted(titles):

           outfile.write('{}\n'.format(title))

           print(title)

def main():

   filename = input('Enter input file name: ')

   dict = readFile(filename)

   if dict is None:

       print('Error: Invalid file name provided: {}'.format(filename))

       return

   print(dict)

   output_filename_1 ='output_keys.txt'

   output_filename_2 ='output_titles.txt'

   output_keys(dict,output_filename_1)

   output_titles(dict,output_filename_2)

main()

Explanation:

You might be interested in
When creating an html document, what do we use to set aside space for content?.
LUCKY_DIMON [66]

AnswerTags:

Explanation:

3 0
2 years ago
Micheal is the project manager in a company. He wants his organization to use technology for higher revenue and productivity. Wh
monitta

Answer:

For higher revenue, the mamagement of income, discounts and all financial matters whereby the use of technology can help by installing a

BUSINESS APPLICATION

4 0
3 years ago
Disadvantages of computer. ​
SVEN [57.7K]

Answer:You cant carry it around like a phone

Explanation:

7 0
3 years ago
How to program chamberlain universal garage door opener?
vodomira [7]
Prior to purchasing the universal garage door remote, verify the brand and model number of the garage door opener are included, and that the frequencies of the opener and the universal remote match. Find the brand and model number that matches the garage door opener. Key that code into the remote and press enter. Test the garage door by pressing the button on the remote. If the code works, the garage door opens and closes on cue
7 0
4 years ago
What is the best practice to do an SEO for a HTML website? Is there any plug-in for this?
frosja888 [35]

<em>Listed below are best practices to do HTML websites that are SEO-friendly: </em>

<em>1. Make neat layout design for the website. -</em><em> Creating a neat layout for HTML pages can make spider crawlers to navigate to your page easily. The messier the page, the harder the spider could navigate. </em>

<em>2. Pages should have unique and keyword rich links. </em><em>- Rename your page with keywords and include these keyword in the URL.  </em>

<em>3. Content must be written with keywords. -</em><em> the more keywords that can be seen in the content, the more possibilities that the spiders can reach your website.</em>

<em>There is no plug-ins needed. Just good practices.</em>

4 0
3 years ago
Other questions:
  • The number of output for a decoder if the input is 4
    14·1 answer
  • The hotspot created by MiFi is password protected and can be used to connect Wi-Fi devices located within ____ feet of the MiFi
    9·1 answer
  • Which two of the following skills are important for a meteorologist
    12·1 answer
  • CIST 1122 Project 2 Instructions
    11·1 answer
  • How long does it take to go 80 miles if you are going 80 mph?
    8·2 answers
  • E-What is the important of Recycle bin?<br>Ans:​
    12·1 answer
  • 9. Which of the following commands is executed with the shortcut 'Ctrl+Z'?
    11·1 answer
  • Adrian wants to run a digital movie clip that his friend shared with him through email. His system has 2 GB of RAM and 20 GB of
    9·1 answer
  • What is the recipe for enchanting table?
    14·2 answers
  • you are tasked with managing multiple servers. you want to manage them all from one server manager interface so you don't have t
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!