def matchingWords(sentence1, sentence2):
words1 = sentence1.strip().split(" ")
words2 = sentence2.strip().split(" ")
score = 0
for word1 in words1:
for word2 in words2:
# print(f"Matchin word {word1} with {word2} ")
if word1.lower() == word2.lower():
score += 1
return score
if __name__ == "__main__":
# print(matchingWords("This is a good", "Python is a good"))
sentences = ["Ashfaq is good boy",
"He work for Eaglesoft", "Eaglesoft is on of the best"]
query = input("Please enter your query:\n")
scores = [matchingWords(query, sentece) for sentece in sentences]
# print(scores)
sortSentScore = [sentScore for sentScore in sorted(
zip(scores, sentences), reverse=True) if sentScore[0] != 0]
# print(sortSentScore)
print(f"{len(sortSentScore)} results found!\n")
for score, item in sortSentScore:
print(f" \"{item}\" with the score of {score}")
No comments:
Post a Comment