Question

4. outputWordPointPairs(pointWordList, filename, toFile) NO return (just prints a formatted list or writes it to file). NOTE: In Python

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1 def outputwordPointPairs (pointwordList, tilenane, toFile): fmt = {: if toFile: + str(len(filenare〕 4] 5} {}\n + + ile-

# CODE Starts here


def outputWordPointPairs(pointWordList, filename, toFile):
fmt = "{:" + str(len(filename) + 4) + "s} {}\n"
if toFile:
file = open(filename + ".txt", 'w')

for p in pointWordList:
s = fmt.format(p[1], p[0])
if toFile:
file.write(s)
else:
print(s, end='')

if toFile:
print('Please check output file {}.txt'.format(filename))


# SAMPLE RUN
pl = [(5, 'obi'), (5, 'nub')]
outputWordPointPairs(pl, 'buoni', True)

Add a comment
Know the answer?
Add Answer to:
In Python 4. outputWordPointPairs(pointWordList, filename, toFile) NO return (just prints a formatted list or writes it...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This application is for you, the shopper in mind. Putting together an itemized shopping list that...

    This application is for you, the shopper in mind. Putting together an itemized shopping list that contains the items you need, the items you want, and the anticipated cost, this program will generate a total price. This way you can decide if your shopping budget fits the bill. Example list: Price List Binder paper: 2.29 Mop: 7.50 Scouring pads: 5 Your application program will create and write a new list to an output file in which the need and wish...

  • This assignment tests your ability to write C programs that handle keyboard input, formatted console output,...

    This assignment tests your ability to write C programs that handle keyboard input, formatted console output, and input/output with text files. The program also requires that you use ctype functions to deal with the logic. In this program, you will input from the user two characters, which should both be letters where the second letter > the first letter. You will then input a file character-by-character and output those letters that fall between the two characters (inclusively) to an output...

  • For Python [25 pts] Write the method divisorList(aList, divisor) that takes in a list with elements...

    For Python [25 pts] Write the method divisorList(aList, divisor) that takes in a list with elements of any data type and a divisor which is in the form of an integer. The output is a sorted list of only the integers that are divisible by the divisor. Example: divisorList([1, 1, 12, 'a', 90, 34], 2) will return [12, 34, 90] since 12, 90, and 34 are all divisible by two. Note that the returned list is sorted from smallest to...

  • QUESTION The ReadFile class opens and reads a text file. The WriteFile class opens and writes...

    QUESTION The ReadFile class opens and reads a text file. The WriteFile class opens and writes to a file. Compile and run these programs. There are several ways to read/write text files. The examples shown here are just one way of achieving this. Look at the API for the BufferedReader class. The readline() method is a simple way to read the text file line by line. It returns null when the end of the file has been reached. https://docs.oracle.com/javase/8/docs/api/java/io/BufferedReader.html Look...

  • the language is python Instructions Forum Tutoring Problem program. Write a function concatenate_files(filename1, filename2, new filename) that concatenates the text from two source files such...

    the language is python Instructions Forum Tutoring Problem program. Write a function concatenate_files(filename1, filename2, new filename) that concatenates the text from two source files such that the text from the file named by argument filename 2 follows the text from filename1. The concatenated text is written to a new file with the name given by new_filename. Your function O must not return anything. We have provided sample input files named part1.txt and part2.txt containing a portion of the text from...

  • Create a Python list (use first three letters of your name followed by the letter L...

    Create a Python list (use first three letters of your name followed by the letter L as the name of the list.) with the following data: 10, 20.0, 50.00, 7000, 7500, 7700, 7800, 8000, 9000, ‘python’. Display the entire list with an appropriate message. Display the 4th element in the list with an appropriate message. Display the first 3 values of the list only. Display all the values starting from the sixth element to the end of the list. Change...

  • Consider the following function: def get_largest(filename): input_file = open(filename, 'r') lines = input_file.readlines() input_file.close() largest =...

    Consider the following function: def get_largest(filename): input_file = open(filename, 'r') lines = input_file.readlines() input_file.close() largest = 0 for line in lines: items_list = line.split() for element in items_list: value = float(element) if value > largest: largest = value return largest The function takes a filename as a parameter and returns the largest number in the file as a float. Modify the above function and use a try-except-else block to handle exceptions that may occur and handle the FileNotFoundError in your...

  • Python 3.6 Question 12 (20 points) Write a function named wordLengths. The function wordLengths takes two...

    Python 3.6 Question 12 (20 points) Write a function named wordLengths. The function wordLengths takes two parameters: 1. inFile, a string that is the name of an input file 2. outFile, a string that is the name of an output file The input file exists when wordLengths is called; wordLengths must create the file outFile. The input file contains only letters and white space For each line of the input file, wordLengths should identify the length of the longest word...

  • C++ (1) Write a program to prompt the user for an input and output file name....

    C++ (1) Write a program to prompt the user for an input and output file name. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs. For example, (user input shown in caps in first line, and in second case, trying to write to a folder which you may not have write authority in) Enter input filename: DOESNOTEXIST.T Error opening input file: DOESNOTEXIST.T...

  • Write a python function score_formatter() that takes one parameter, which is a formatted string that contains...

    Write a python function score_formatter() that takes one parameter, which is a formatted string that contains information about the score received by a student in a particular subject. The function analyzes the string and returns a reformatted string for the score. You will need to use the function re.sub that is discussed in the lecture notes. If the string does not match the pattern, the function returns the string "error". The input string is always given in the format specified...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT