Solution 1

def positions(a_string, first_word, second_word, third_word):
    result = ''
    if first_word in a_string:
        result += str(a_string.index(first_word))
    else:
        result += '-'
    result += ','

    if second_word in a_string:
        result += str(a_string.index(second_word))
    else:
        result += '-'
    result += ','

    if third_word in a_string:
        result += str(a_string.index(third_word))
    else:
        result += '-'

    return result

Positions

Write a function positions that receives a string and 3 words, and gives you the positions of those words in the original string. Example:

# Positions:
#         0                         26      34
phrase = "Python is good. Python is Wise. I like Python"
positions(phrase, 'Python', 'Wise', 'like')  # "0,26,34"

If the word doesn't exist in the original string, it should backfill using dashes. Example:

# Positions:
#         0                         26
phrase = "Python is good. Python is Wise. I like Python"
positions(phrase, 'Python', 'Wise', 'Ruby')  # "0,26,-" (Ruby doesn't exist)

Test Cases

test one occurrence third word - Run Test

def test_one_occurrence_third_word():
    # Positions:
    #         0                         26      34
    phrase = "Python is good. Python is Wise. I like Python"
    assert positions(phrase, 'Javscript', 'Ruby', 'Wise') == "-,-,26"

test two occurrences missing first - Run Test

def test_two_occurrences_missing_first():
    # Positions:
    #         0                         26      34
    phrase = "Python is good. Python is Wise. I like Python"
    assert positions(phrase, 'Ruby', 'Wise', 'like') == "-,26,34"

test two occurrences missing third - Run Test

def test_two_occurrences_missing_third():
    # Positions:
    #         0                         26      34
    phrase = "Python is good. Python is Wise. I like Python"
    assert positions(phrase, 'Python', 'Wise', 'Ruby') == "0,26,-"

test one occurrence first word - Run Test

def test_one_occurrence_first_word():
    # Positions:
    #         0                         26      34
    phrase = "Python is good. Python is Wise. I like Python"
    assert positions(phrase, 'Python', 'Javascript', 'Ruby') == "0,-,-"

test three occurrences - Run Test

def test_three_occurrences():
    # Positions:
    #         0                         26      34
    phrase = "Python is good. Python is Wise. I like Python"
    assert positions(phrase, 'Python', 'Wise', 'like') == "0,26,34"

test one occurrence second word - Run Test

def test_one_occurrence_second_word():
    # Positions:
    #         0                         26      34
    phrase = "Python is good. Python is Wise. I like Python"
    assert positions(phrase, 'Javscript', 'like', 'Ruby') == "-,34,-"
def positions(a_string, first_word, second_word, third_word): pass