Programming Exercise #6 (File Analysis): a.Name your Python file FileAnalysis.py
ID: 3835070 • Letter: P
Question
Programming Exercise #6 (File Analysis):
a.Name your Python file FileAnalysis.py
b.There are two text files provided with this lab assignment, textFile1.txt and textFile2.txt. The files contain one word per line.
c.Hint: Read these lines into lists, and strip off the newline character at the end of each one, then read the words from the list into sets.
d.The first two lines of display should contain the words in each set.
Here is a sample of what your program execution might look like. Yours does not have to look exactly like this, as long as it works correctly.
Explanation / Answer
def getWordList(filename):
words = []
with open(filename, "r") as fh:
for line in fh:
words.append(line.strip())
return words
list1 = getWordList("textFile1.txt")
list2 = getWordList("textFile1.txt")
set1 = set(list1)
set2 = set(list2)
print(set1)
print(set2)
# code link: https://paste.ee/p/vQHoH
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.