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
Andreyy89
3 years ago
6

9.21 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:
Engineering
1 answer:
natka813 [3]3 years ago
8 0

The following code or the program will be used

<u>Explanation:</u>

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()

You might be interested in
Injector orifice patterms and size will affect propellant mixing and distribution. a)-True b)-False
alina1380 [7]

Answer: True

Explanation: Injector orifice is the factor which describes the size of the opening of the injector .There are different pattern and size of the opening for the injector which affects the mixture of the chemical substance that is used for the production of the energy that is known as propellant.

The pattern and size of the orifice will define the variation in the amount of energy that could be produced.Thus the statement given is true.

4 0
3 years ago
Which of the following does a finding of no significant impact (FONSI) negate the need for?
garik1379 [7]
4 environmental accessment
5 0
3 years ago
Show 2 reasons each on how Netflix shows a humane design and an addictive design.
larisa86 [58]

Answer:

Explanation:

1. It is a humane design because of the way it provides people entertainment as well as healing in some situations. Netflix provides entertainment mainly towards realistic situations which also points out the humane design.

2. It is an addictive design because even though the pros of being helpful to certain people it can also be addicting to the mind especially since it is a design where there endless amount of shows you can watch over and over again which that type of action can lead to addiction.

6 0
3 years ago
A pipe of 0.3 m outer diameter at a temperature of 160°C is insulated with a material having a thermal conductivity of k = 0.055
Alekssandra [29.7K]

Answer:

Q=0.95 W/m

Explanation:

Given that

Outer diameter = 0.3 m

Thermal conductivity of material

K= 0.055(1+2.8\times 10^{-3}T)\frac{W}{mK}

So the mean conductivity

K_m=0.055\left ( 1+2.8\times 10^{-3}T_m \right )

T_m=\dfrac{160+273+40+273}{2}

T_m=373 K

K_m=0.055\left ( 1+2.8\times 10^{-3}\times 373 \right )

K_m=0.112 \frac{W}{mK}

So heat conduction through cylinder

Q=kA\dfrac{\Delta T}{L}

Q=0.112\times \pi \times 0.15^2\times 120

Q=0.95 W/m

4 0
3 years ago
Kam
jolli1 [7]
I think D i’m not sure
7 0
3 years ago
Other questions:
  • Use the results of Prob. 5–82 for plane strain near the tip with u 5 0 and n 5 13. If the yieldstrength of the plate is Sy, what
    5·1 answer
  • A very large plate is placed equidistant between two vertical walls. The 10-mm spacing between the plate and each wall is filled
    11·1 answer
  • Item110pointseBook HintPrintReferences Check my work Check My Work button is now disabled5Item 1Item 1 10 pointsAn ideal Diesel
    10·1 answer
  • A minor road intersects a major 4-lane divided road with a design speed of 50 mph and a median width of 12 ft. The intersection
    13·1 answer
  • A railroad runs form city A to city B, a distance of 800km, through mountainous terrain. The present one-way travel time (includ
    13·1 answer
  • Airplanes are the only way that people can take flight.<br> A. True<br> B. False
    14·2 answers
  • Just to let you know Christmas is in 10 days&lt;3<br><br> lol
    6·2 answers
  • While discussing the diagnosis of an EI system in which the crankshaft and camshaft sensor tests are satisfactory but a spark te
    13·1 answer
  • Respond with TRUE if the symbol of the valve shown belows
    5·1 answer
  • A torque T 5 3 kN ? m is applied to the solid bronze cylinder shown. Determine (a) the maximum shearing stress, (b) the shethe 1
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!