Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. # Two files contain words separated by spaces
  2. # Please find same word in both files (uppercase
  3. # lowercase letters are not important).
  4. # Received list is printed in the file. Use Functional Programming.
  5.  
  6. def read_data(file_path):
  7. with open(file_path, "r") as file:
  8. words = []
  9. # we read the words in the file,
  10. # words separated by one space
  11. for line in file:
  12. words += line.split()
  13. print(words, flush=True)
  14. return words
  15.  
  16.  
  17. def find_matching(list1, list2):
  18. matching = []
  19. for item_in_1 in list1:
  20. for item_in_2 in list2:
  21. if item_in_1.lower() == item_in_2.lower():
  22. matching.append(item_in_1)
  23. return matching
  24.  
  25. words1 = read_data("data.txt")
  26. words2 = read_data("data2.txt")
  27. matching = find_matching(words1, words2)
  28. print(matching)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement