HOMEWORK IX-a:
code:
output:
text.txt
HOMEWORK IX-b:
code:
output:
first_file.txt
second_file.txt
home1.py
# YOUR NAME
file_input = input("Input the file path/name: ")
# there are no mentions in question to remove punctuations or to
make lower cases.
with open(file_input, 'r') as f:
fp = f.read().split()
# unique word
fp = set(fp)
fp = sorted(fp)
print(fp)
print("Number of unique words: {0}".format(len(fp)))
home2.py
#YOUR NAME
from string import punctuation
file1 = input("Input the first file path/name: ")
file2 = input("Input the second file path/name: ")
with open(file1, 'r') as f:
fp1 = f.read().lower()
for i in punctuation:
fp1 = fp1.replace(i, "")
fp1 = set(fp1.split())
with open(file2, 'r') as f:
fp2 = f.read().lower()
for i in punctuation:
fp2 = fp2.replace(i, "")
fp2 = set(fp2.split())
union = fp1.union(fp2)
intersection = fp1.intersection(fp2)
#first = fp1-fp2
first = fp1.difference(fp2)
second = fp2.difference(fp1)
either_first_or_second = fp1.symmetric_difference(fp2)
print("-"*60)
print("Union of both sets: ")
print(union)
print("-"*60)
print("Intersection of both sets: ")
print(intersection)
print("-"*60)
print("Unique words only in first file: ")
print(first)
print("-"*60)
print("Unique words only in second file: ")
print(second)
print("-"*60)
print("Unique words in either of them but not in both: ")
print(either_first_or_second)
print("-"*60)
test.txt
Knowledge nay estimable questions repulsive daughters boy.
Solicitude gy way unaffected expression for. His mistress ladyship
required off horrible disposed rejoiced. Unpleasing pianoforte
unreserved as oh he unpleasant no inquietude insipidity. Advantages
can discretion possession add favourable cultivated admiration far.
Why rather assure how esteem end hunted nearer and before. By an
truth after heard going early given he. Charmed to it excited
females whether at examine. Him abilities suffering may are yet
dependent.
Sex reached suppose our whether. Oh really by an manner sister so.
One sportsman tolerably him extensive put she immediate. He abroad
of cannot looked in. Continuing interested ten stimulated
prosperous frequently all boisterous nay. Of oh really he extent
horses wicket.
Tiled say decay spoil now walls meant house. My mr interest
thoughts screened of outweigh removing. Evening society musical
besides inhabit ye my. Lose hill well up will he over on.
Increasing sufficient everything men him admiration unpleasing sex.
Around really his use uneasy longer him man. His our pulled nature
elinor talked now for excuse result. Admitted add peculiar get joy
doubtful.
Another journey chamber way yet females man. Way extensive and
dejection get delivered deficient sincerity gentleman age. Too end
instrument possession contrasted motionless. Calling offence six
joy feeling. Coming merits and was talent enough far. Sir joy
northward sportsmen education. Discovery incommode earnestly no he
commanded if. Put still any about manor heard.
first_file.txt
Knowledge nay estimable questions repulsive daughters boy.
Solicitude gy way unaffected expression for. His mistress ladyship
required off horrible disposed rejoiced. Unpleasing pianoforte
unreserved as oh he unpleasant no inquietude insipidity. Advantages
can discretion possession add favourable cultivated admiration far.
Why rather assure how esteem end hunted nearer and before. By an
truth after heard going early given he. Charmed to it excited
females whether at examine. Him abilities suffering may are yet
dependent.
Sex reached suppose our whether. Oh really by an manner sister so.
One sportsman tolerably him extensive put she immediate. He abroad
of cannot looked in. Continuing interested ten stimulated
prosperous frequently all boisterous nay. Of oh really he extent
horses wicket.
second_file.txt
Tiled say decay spoil now walls meant house. My mr interest
thoughts screened of outweigh removing. Evening society musical
besides inhabit ye my. Lose hill well up will he over on.
Increasing sufficient everything men him admiration unpleasing sex.
Around really his use uneasy longer him man. His our pulled nature
elinor talked now for excuse result. Admitted add peculiar get joy
doubtful.
Another journey chamber way yet females man. Way extensive and
dejection get delivered deficient sincerity gentleman age. Too end
instrument possession contrasted motionless. Calling offence six
joy feeling. Coming merits and was talent enough far. Sir joy
northward sportsmen education. Discovery incommode earnestly no he
commanded if. Put still any about manor heard.
Homework IX-a Write a program that opens a text file, whose name you enter at the keyboard You wi...
write a python program that prompts the user for a name of a text file, opens that file for reading , and tracks the unique words in a file and counts how many times they occur in the file. Your program should output the unique words and how often they occur in alphabetical order. Negative testing for a file that does not exist and an empty file should be implemented.
JAVA Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it. The input files are assumed to be in CSV format. The input files contain a list of integers on each line separated by commas. The program should read each line, sort the numbers and print the comma separated list of integers on the console. Each sorted list of integers from the same line should be printed together...
Need some help on this Python Problem called "unique words" the text.txt file can be any .txt file with words in it. Write a program that opens a specified text file and then displays the number of unique words in the text file after stripping all the white spaces, comma, and the punctuation marks and list of all the unique words found in the file. The list should be sorted in alphabetical order. The program should handle the ‘file not...
Python: The attached text file: https://drive.google.com/open?id=1Hcj4Ey4NbKHn5-vyF-foR3iny0aX8y1c Unique Words Write a program that opens a specified text file and then displays the number of unique words in the text file after stripping all the white spaces, comma, and the punctuation marks and a list of all the unique words found in the file. The list should be sorted in alphabetical order. The program should handle the ‘file not found’ error. Store each word as an element of list. Be sure not...
Python 3:Write a program that inputs a text file. The program should print the unique words in the file in alphabetical order. Write a program that inputs a text file. The program should print the unique words in the file in alphabetical order An example file along with the correct output is shown below: example.txt the quick brown fox jumps over the lazy dog Enter the input file name: example.txt brown dog fox jumps lazy over quick the
in c++ please. Write a program that reads the contents of a text file. The program should create a map in which the keys are the individual words found in the file and the values are the number of times each word appears. For example, if the word "the" appears 128 times, the map would contain an element with "the" as the key and 128 as the value. The program should either display the frequency of each word or create...
Write a complete Python program with prompts for the user for the main text file (checks that it exists, and if not, output an error message and stop), for any possible flags (including none), and for any other input that this program may need from the user: split has an option of naming the smaller files head_tail list the first 10 lines (default) and the last 10 lines (default) in order of the given text file flag: -# output #...
Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. 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 opening any of the 3 For example, (user input shown in caps in first line) Enter first...
Write a program that opens a specified text file and then displays a list of all the unique words found in the file. Hint: Store each word as an element of a set. USING PYTHON Please provide a screenshot of the input
Write a program IN PYTHON that checks the spelling of all words in a file. It should read each word of a file and check whether it is contained in a word list. A word list available below, called words.txt. The program should print out all words that it cannot find in the word list. Requirements Your program should implement the follow functions: main() The main function should prompt the user for a path to the dictionary file and a...