US · interviewqs.com

Counting the distance between words in Python

Python, String Manipulation,


This email was sent

Is this your brand on Milled? Claim it.

InterviewQs

Counting the distance between words in Python

Python String Manipulation

Forward this email to a friend or colleague and challenge them to solve it.

Hi, 

Suppose you are given two words, word_1 and word_2, as well as a string containing them, called your_string.

Given this, write a function using Python to find the minimum distance between word_1 and word_2. For the context of this question, distance is defined as the number of words between word_1 and word_2.

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.


 

You’ve accumulated 163 questions since joining our email list. Create a premium account to access detailed solutions to each problem (including this one) + our new Case studies.


Was this email forwarded to you? You can join our list here to receive questions

How did you like today's question?

15411 Boischatel, Montreal, QC, H9H1Y7, Canada
Don't want to get these emails anymore? We'll forgive you if you unsubscribe
Are you sure?

Lists help you organize the brands that you care about. Your lists are private to you.