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

Answers

Answer 1
Answer:

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:


Related Questions

Write a Comparator that compares String objects by the number of words they contain. Consider any nonwhitespace string of characters to be a word. For example, "hello" comes before "I see", which comes before "You can do it"
Make a program that asks for input from the user, apply eval to this input, and print out the type of the resulting object and its value. Test the program by providing five types of input: an integer, a real number, a complex number, a list, and a tuple.
What can quantum computers do more efficiently than regular computers?
What is the tool that is used to automatically search New information on the internet and organize if for future searches?
(5 pt.) The name of a variable in the C programming language is a string that can contain uppercase letters, lowercase letters, digits, or underscores. Furthermore, the first character in the string must be a letter, either uppercase or lowercase, or an underscore. If the name of a variable is determined by its first 8 characters, how many different variables can be named in C

python Write a function that computes a future investment value at a given interest rate for a specified number of years. The future investment is determined using the formula in Programming Exercise 2.19 in Chapter 2 Programming Exercise from the Book.

Answers

Answer:

def future_investment_value(investment, monthly_interest_rate, years):

  print("Years\tFuture Value")

  print("- - - - - - - - - - -")

  for i in range(1, years+1):

      future_value = investment * ((1 + monthly_interest_rate) ** (12 * i))

      print(i, "\t\t", format(future_value, ".2f"))

investment = float(input("Enter the invesment amount: "))

interest = float(input("Enter the annual interest rate: "))

year = int(input("Enter the year: "))

future_investment_value(investment, interest/1200, year)

Explanation:

Inside the function:

- In the for loop that iterates through the years, calculate the future value using the formula and print the results

Then:

- Ask the user for the investment, annual interest rate, and year

- Call the function with the given inputs

A vowel word is a word that contains every vowel. Some examples of vowel words are sequoia, facetious, and dialogue. Determine if a word input by the user is a vowel word.

Answers

Answer:

vowels = ("a", "e", "i", "o", "u")

word = input("Enter a word: ")

is_all = True

for c in vowels:

   if c not in word:

       is_all = False

if is_all == True:

   print(word + " is a vowel word.")

else:

   print(word + " is not a vowel word.")

Explanation:

Initialize a tuple, vowels, containing every vowel

Ask the user to enter a word

Initially, set the is_all as True. This will be used to check, if every vowel is in word or not.

Create a for loop that iterates through the vowels. Inside the loop, check if each vowel is in the word or not. If one of the vowel is not in the vowels, set the is_all as False.

When the loop is done, check the is_all. If it is True, the word is a vowel word. Otherwise, it is not a vowel word.

Which file is used to configure the various mounting options of a filesystem upon boot?a. /etc/mount
b. /etc/fstab
c. /var/filesystem
d. /boot/config

Answers

Answer:

B. /etc/fstab file.

Explanation:

The /var/filesystem file is a subdirectory of the root directory of a linux operating system, used to store files during the operation of a computer system.

The /boot/config file is  a file directory used to store system configuration parameters which can be accessed by the GPU before the installation of the ARM CPU and linux.

The /etc/mount (or /etc/mtab) and /etc/fstab are used to show the list of mounted volumes. The /etc/mtab gives details of already mounted volumes, but the /etc/fstab shows the list of possible volumes to be mounted upon the boot of the system.

This problem will be discussed in Lab6. In Lab6, the TAs will also discuss about the solution of Function Problem 1 that required you to write several functions. Additionally, the last week's lab problems on loop will be discussed too, if you need more help on them. See the deadline. You should try your best to complete it within the lab time. First n prime numbers: Write a program that takes a positive integer n as input and prints all the prime numbers from 1 to n.

Answers

Answer:

C++.

Explanation:

#include <iostream>

using namespace std;

////////////////////////////////////////////////////////////////

void printPrime(int n) {

   if (n > 0) {

       cout<<2<<endl;

       

       for (int i=3; i<=n; i++) {

          bool isPrime = true;

           

           for (int j=2; j<i; j++) {

               if (i % j == 0) {

                   isPrime = false;

                   break;

               }

           }

           

           if (isPrime == true)

               cout<<i<<endl;

       }

   }

   else {

       cout<<"Invalid input";

   }

}

int main() {

   int n;

   cout<<"Enter positive integer: ";

   cin>>n;

   printPrime(n);

   return 0;

}

Which is true of diagnosing and troubleshooting? Diagnosing attempts to identify the source of a problem, while troubleshooting looks for the nature of the problem. Diagnosing is used to fix problems with hardware, while troubleshooting is used to fix problems in program code. Diagnosing looks for the nature of the problem, while troubleshooting attempts to identify the source of the problem. Diagnosing is used to fix problems in program code, while troubleshooting is used to fix problems with hardware.

Answers

Answer:

the answer is c

Explanation:

i just took the test

Answer:c

Explanation: because Diagnosing looks for the nature of the problem, while troubleshooting attempts to identify the source of the problem.

Discuss the relationship of culture and trends?

Answers

A good thesis would be something like “Modern culture is heavily influenced by mainstream trends” and just building on it.