Skip to content

Commit bf26d2c

Browse files
authored
Create distance_phrases.py
1 parent f40ddf8 commit bf26d2c

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Diff for: distance_phrases.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from typing import List
2+
3+
'''
4+
take a function that recieve and input a list with strings and a distance and return if the input contains
5+
the list of of strings with less or equal between other phrases.
6+
'''
7+
8+
def check_distance(input: str, items: List[str], distance: int) -> bool:
9+
entries = input.split(' ');
10+
current_item = 0
11+
positions = []
12+
for i, entry in enumerate(entries):
13+
if (entry == items[current_item]):
14+
positions.append(i)
15+
if (len(positions) > 1 and positions[-1] - (positions[-2] + 1) > distance):
16+
break;
17+
current_item += 1
18+
19+
if (len(items) > len(positions)):
20+
return False
21+
22+
return True
23+
24+
25+
print(check_distance('should i I take one two aspirine second i or i', ['i', 'take', 'aspirine', 'i', 'i'], 0)) # False
26+
27+
print(check_distance('should i I take one two aspirine second i or i', ['i', 'take', 'aspirine', 'i', 'i'], 2)) # True
28+
29+
print(check_distance('should i I take one two aspirine second second second i or i', ['i', 'take', 'aspirine', 'i', 'i'], 2)) # False
30+
31+
print(check_distance('should i I take one two aspirine second second second i or i', ['i', 'take', 'aspirine', 'i', 'i'], 5)) # True

0 commit comments

Comments
 (0)