Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #ch 8 p 10 - Judah Mismash
  2. #print common words from two text files.
  3.  
  4. def main() :
  5. #Read the files.
  6. words1 = fileWords()
  7. words2 = fileWords()
  8.  
  9. common = words1.interesction(words2)
  10. print("Common words: ")
  11. for word in sorted(common) :
  12. print(" ", word)
  13.  
  14. def fileWords() :
  15. filename = input("Please enter the text file name: ")
  16. inf = open(filename, "r")
  17.  
  18. words = set()
  19. for line in inf :
  20. parts = line.split()
  21. for word in parts:
  22. words.add(word)
  23.  
  24. return words
  25.  
  26. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement