Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this pyhthon assignment, you are given a text file with one sentence per line

ID: 3820892 • Letter: I

Question

In this pyhthon assignment, you are given a text file with one sentence per line, however, the whitespaces from the sentences are missing. You are going to design and develop an algorithm to restore the lost whitespaces. Fortunately, all or most of the individual words from the original sentences are available in a separate file that you have full access to, one word per line.

You are given 2 files, sentence.txt and word.txt.

File “sentence.txt” contains the sentences (without whitespaces), one per line, to be restored.

File “word.txt” contains most of the individual words from the original sentences, one per line,

all lowercase.

Reconstruct each sentence from file “sentence.txt” based on the word from file “word.txt”.

Two possible outcomes: a sentence can be either fully reconstructed or partially reconstructed

Given words from “word.txt” as follows:

a. “fine”, “this”, “is”, “fine”, “a”, “i”, “beautiful”, “day”, “cannot” and “be”.

A sentence is fully reconstructed when ALL the words from the sentence are found in word file.

print out the results with a single whitespace inserted in between words

Ex: “iamfine” -> “I am fine”

Ex: “thisisabeautifulday” -> “this is a beautiful day”

If a sentence cannot be fully restored, return the “raw” sentence as it is.

Ex: “cannotberestored” -> “cannotberestored”

Ex: “thisisanotherbeautifulday” -> “thisisanotherbeautifulday”

Save ALL results to another separate file in the order that were read from file “sentence.txt”

To handle punctuation marks:

. (period)

; (semi-colon)

: (colon)

- (dash)

? (question mark)

! (exclamation mark)

, (comma)

“ (double quote)

‘ (single quote)

( (open round bracket)

) (close round bracket)

Examples: “grape,orange,anddark-chocolate.” -> “grape, orange, and dark-chocolate.”

Explanation / Answer

import re def correction(string): list=[] for i in string: if i!=" ": list.append(i) else if i==" ": k=i+1 if k==" ": k="" list.append(i) s=' '.join(list) return s strn=input("Enter the string: ").split() print (correction(strn)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote