Probably a duplicate but after 15 min I couldn't find an answer to my question, probably my poor coding terminology.
what is it about my logic that I'm incorrectly passing my arguments? Please refrain from chastising my choice code itself, I'm not very good at this and I know it.
The program is supposed to:
- a)create a set of all the unique words in file1 and print them
- b)create a set of all the unique words in file2 and print them
- c)print all of the words that are contained in both files
- d)print all of the unique words that are contained in either file
- e)print all of the words that are contained in file1 but not file2
- f)print all of the words that are contained in file2 but not file1
- g)print all of the words that are contained in either file but not both
Items (a) and (b) should be produced by the function that creates the sets; there should be a separate function for each of the others. btw is case it somehow helps file 1 is:
- "Now is the time for all good men to come to the aid of their party."
file 2 is:
"It is time to go to the party."
def main(): file1()#obtain file1 uniquness file2()#obtain file2 uniqueness print("C) Words that appear in both files: "+str(set_1&set_2)+'\n')#addd them print("D) Unique words that appear in either file: "+str(set_1|set_2)+'\n') print("E) Words that appear in file1 but not file2: "+str(set_1-set_2)+'\n') #subtract words found in 2 from 1 print("F) Words that appear in file2 but not file1: "+str(set_2-set_1)+'\n') print("G) Words that appear in either file but not both: "+str(set_1^set_2)+'\n') def file1(): file_1=open('file1.txt', 'r') file_1=file_1.readline() setlist_1=file_1.split()#convert file 1 set_1=set() for word in setlist_1: word=word.lower() word=word.rstrip("\n")#process uniqueness set_1.add(word) print("A) Unique words in file1: "+str(set_1)+'\n')#print A return set_1 def file2(): file_2=open('file2.txt','r') file_2=file_2.readline()#convert file 2 setlist_2=file_2.split() set_2=set() for words in setlist_2: words=words.lower()#process uniqueness words=words.rstrip("\n") set_2.add(words) print("B) Unique words in file2: "+str(set_2)+'\n')#print B return set_2 main()