0

I need to write a program that will determine the length of the spaces between successive occurrences of a given character. If the occurrences are adjacent, the space between them is considered to be 1.

I can only calculate between two signs

text = input ('enter text')
find = input ('enter a search character')
x = text.find(find)

y = text.rfind(find)
   
dist = text.rfind(find) - text.find(find)
print(dist)
Maria
  • 3
  • 2

1 Answers1

0

This code will output the distances into a list.

text = "Maybe it's in the gutter, where I left my lover. What an expensive fate."
find = input('Enter a search character')

spaces_list = [len(x) + 1 for x in text.split(find)[1:-1]]
print(spaces_list)

Output

>>> Enter a search character
>>> t

>>> [7, 6, 1, 16, 15, 17]