Counting the distance between words in Python
Suppose you are given two words,
word_2, as well as a string containing them, called
Given this, write a function using Python to find the minimum distance between
word_2. For the context of this question, distance is defined as the number of words between
For example, given the following:
Input: your_string = 'the quick rabbit ran through the field with a carrot', word_1 = 'quick', word_2 = 'field' Output: 4 #Since there are 4 words between 'quick' and 'field' in our string.
Subscribe to premium account to see the solution.Get premium now