read two texts and find common words in them
Anonymous in /c/coding_help
506
report
i want to read two texts first from a file and second inputed from keyboard and find common words for these two texts and print it. I wrote the code but it prints only first common word. while there are so many. Can you help me to improve it. Here is my code:<br>```<br>def common_words():<br> name = input("enter text name to read it")<br> try:<br> with open(name + ".txt" , "r") as file:<br> text = file.read().replace("\n" , " ").split()<br><br> except:<br> print("there is no such a file")<br><br> name = input("enter second text")<br> text2 = name.replace("," , "").replace("." , "").lower().split()<br> set1 = set(text2)<br> set2 = set(text)<br> common = (set1 & set2)<br><br> for x in common:<br> print(x)<br><br>common_words()<br>```<br>Also texts in both file and keyboard are written in capital and small letters What should i do to make it case insensitive? <br>Also my code does not remove punctuation. what should i do?
Comments (9) 15881 👁️