Skip to content

Commit

Permalink
Create distance_phrases.py
Browse files Browse the repository at this point in the history
  • Loading branch information
masterpol authored Nov 15, 2023
1 parent f40ddf8 commit bf26d2c
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions distance_phrases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from typing import List

'''
take a function that recieve and input a list with strings and a distance and return if the input contains
the list of of strings with less or equal between other phrases.
'''

def check_distance(input: str, items: List[str], distance: int) -> bool:
entries = input.split(' ');
current_item = 0
positions = []
for i, entry in enumerate(entries):
if (entry == items[current_item]):
positions.append(i)
if (len(positions) > 1 and positions[-1] - (positions[-2] + 1) > distance):
break;
current_item += 1

if (len(items) > len(positions)):
return False

return True


print(check_distance('should i I take one two aspirine second i or i', ['i', 'take', 'aspirine', 'i', 'i'], 0)) # False

print(check_distance('should i I take one two aspirine second i or i', ['i', 'take', 'aspirine', 'i', 'i'], 2)) # True

print(check_distance('should i I take one two aspirine second second second i or i', ['i', 'take', 'aspirine', 'i', 'i'], 2)) # False

print(check_distance('should i I take one two aspirine second second second i or i', ['i', 'take', 'aspirine', 'i', 'i'], 5)) # True

0 comments on commit bf26d2c

Please sign in to comment.