-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject07_SearchEngine.py
More file actions
27 lines (23 loc) · 992 Bytes
/
Project07_SearchEngine.py
File metadata and controls
27 lines (23 loc) · 992 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def mathingWords(sentence1, sentence2):
words1 = sentence1.strip().split(" ")
words2 = sentence2.strip().split(" ")
score = 0
for word1 in words1:
for word2 in words2:
# print(f"Matching {word1} with {word2}")
if word1.lower() == word2.lower():
score += 1
return score
if __name__ == "__main__":
# mathingWords("This is good", "python is good")
sentences = ["python is a good", "this is snake",
"harry is a good boy", "Subscribe to code with harry"]
query = input("Please enter the query string\n")
scores = [mathingWords(query, sentence) for sentence in sentences]
# print(scores)
sortedSentScore = [sentScore for sentScore in sorted(
zip(scores, sentences), reverse=True) if sentScore[0] !=0 ]
# print(sortedSentScore)
print(f"{len(sortedSentScore)} results found!")
for score, item in sortedSentScore:
print(f" \"{item}\": with a score of {score}")