python
2. fileanalysis.py (30 points)
Write a program that reads the contents of two files and compares them in the following ways:
a. It should display a list of all the words (unique) containing in both files
b. It should display a list of words that appear in both files.
c. It should display a list of words that appear in the first file but not in the second.
d. It should display a list of words that appear in the second file but not in the first .
e. It should display a list of words that appear in either the first or the second files, but not both.
Hints:
Define main()
Get input text of first file and create set containing its unique words. i.e set1 = set(words1) Use 'first_file.txt' file attached under module -> input file for assignment section
Get input text of first file and create set containing its unique words i.e. set2 = set(words2) Use 'second_file.txt' file attached under module -> input file for assignment section
Obtain union of the sets and print the items in it. i.e. union = set1.union(set2) (use a for loop to print the results )
Obtain the intersection of the sets and print the items in it. i.e. intersection = set1.intersection(set2) (use a for loop to print the results )
Obtain the difference between set1 and set2 and print the items in it. i.e. difference1 = set1.difference(set2) (use a for loop to print the results )
Obtain the difference between set2 and set1 and print the items in it. i.e. difference2 = set2.difference(set1) (use a for loop to print the results )
Obtain the symmetric difference between set1 and set2 and print the items in it. i.e. sym_diff = set1.symmetric_difference(set2) (use a for loop to print the results )
Sample output:
Enter the name of the first input file: first_file.txt Enter the name of the second input file: second_file.txt These are the unique words that are contained in both files: jump brown over Jack quick, quick jumps the candlestick. The nimble, dog. lazy be fox
These are the words that appear both files: over the
These are the words that appear in the first file but do not appear in the second file: brown quick jumps The dog. lazy fox
These are the words that appear in the second file but do not appear in the first file: jump Jack quick, candlestick. nimble, be
These are the words that appear in the first file or the second file but do not appear in the both files: jump Jack brown quick, lazy quick candlestick. jumps The dog. nimble, be fox