-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimalrity_between_texts.py
More file actions
48 lines (30 loc) · 1.08 KB
/
simalrity_between_texts.py
File metadata and controls
48 lines (30 loc) · 1.08 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import difflib
import re
def similartiy_between_text(input1, input2):
return(difflib.SequenceMatcher(None, input1, input2).ratio())
def similartiy_between_text_matchedsequence(input1, input2):
return(difflib.SequenceMatcher(None, input1, input2).get_matching_blocks())
print("Ratio", similartiy_between_text("Hello There", "Hello Here"))
print("Longest Match", similartiy_between_text_matchedsequence(
"Hello There", "Hello Here"))
"""
Genius Robot
Alter the speak method so that it returns the sum of numbers for queries containing the word "sum" and two integers.
Examples of usage:
robot = Robot()
print(robot.speak("what is the sum of 1 and 2"))
print(robot.speak("what is the sum of 8 and 10"))
The output of that would be:
3
18
"""
class Robot():
def __init__(self) -> None:
pass
def speak(self, query):
if 'sum' in query:
numbers = re.findall(r"\b\d+\b", query)
return sum([float(x) for x in numbers])
robot = Robot()
print(robot.speak("what is the sum of 1 and 2"))
print(robot.speak("what is the sum of 8 and 10"))