Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Two files contain words separated by spaces
- # Please find same word in both files (uppercase
- # lowercase letters are not important).
- # Received list is printed in the file. Use Functional Programming.
- def read_data(file_path):
- with open(file_path, "r") as file:
- words = []
- # we read the words in the file,
- # words separated by one space
- for line in file:
- words += line.split()
- print(words, flush=True)
- return words
- def find_matching(list1, list2):
- matching = []
- for item_in_1 in list1:
- for item_in_2 in list2:
- if item_in_1.lower() == item_in_2.lower():
- matching.append(item_in_1)
- return matching
- words1 = read_data("data.txt")
- words2 = read_data("data2.txt")
- matching = find_matching(words1, words2)
- print(matching)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement