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]
2 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]2 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
Which technique is best suited to create technical drawings?
Tema [17]

Answer:

Mechanical pencils.

Clutch pencils.

Technical pens.

Rulers.

Compass.

Drawing boards.

Erasers.

Sharpeners.

Explanation:

'What makes a great Technical Drawing? ' Technically correct, accurate, complete, consistent and unambiguous. Check the brief (a lot – and at all stages of the drawing process).

8 0
2 years ago
Uuhdcnkhbbbbhbnbbbbnnnnnnnnnfddjkjfs
Anna35 [415]

Answer:

The answer is "Option c"

Explanation:

In PHP to remove all the session variables, we use the session_destroy() function. It doesn't take any argument is required and then all sessions variables could be destroyed by a single call. If a particular clinical variable is now to be destroyed, the unset() function can be applied to unset a session variable. Its session doesn't unset or unset the session cookie by either of the local variables associated with it.

6 0
2 years ago
When you heat a pot on a stove, the handle gets warm. which type of heat transfer is possible
valina [46]

Answer:

conduction

Explanation:

The handle will warm up until it's total heat losses equal the total heat coming in. Heat comes in mostly by conduction from the body of the pot.

5 0
3 years ago
Read 2 more answers
Choose the two main capabilities involved in visual literacy
andreyandreev [35.5K]

The two main capabilities involved in visual literacy are:

<span>1)   </span>Communication through use of visual elements.

<span>2)   </span>Interpret meaning from visual elements.

<span>Visual literacy is the capacity to decipher, arrange, and make significance from data displayed as a picture, broadening the importance of proficiency, which means understanding of a composed or printed content.</span>

7 0
2 years ago
Select the correct navigational path to set the name for a cell range.
S_A_V [24]

Answer: formula tab, defined names, name manager

Explanation:

ed 2020

6 0
2 years ago
Read 2 more answers
Other questions:
  • To change to the completed application’s directory, we opened a command window and used the ________ command to change to the di
    7·1 answer
  • 3) An example of interactive web page is<br>​
    11·1 answer
  • What is processor, memory RAM, cDRAM,DVD RAM,video card​
    9·1 answer
  • Once artwork is inserted into a placeholder, it can be moved around on a slide. True False
    9·1 answer
  • What function should be entered into B7 to calculate the total budget
    15·2 answers
  • which three objects can be linked or embedded in a word document? A. worksheets, margins, colors B. charts, worksheets, images C
    7·1 answer
  • Select the correct word to complete the sentence
    11·2 answers
  • What type of display allows the user to access a large amount of vocabulary in one device, uses spelling to convey the message,
    10·1 answer
  • Cual es la fiabilidad de la innovacion tecnologica
    15·1 answer
  • Choose all that apply.
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!