Skip to contentKEEP THE CRAFTTHE SANCTUARY

Reverse One Slice Segment

Reverse only text[start:end] by cutting the string into three slices and joining them back.

The problem

Implement reverse_slice_segment(text, start, end). Return a new string in which only text[start:end] is reversed; the characters before start and from end onward stay where they are. For example, ("abcdef", 1, 5) gives "aedcbf". Inputs satisfy 0 <= start <= end <= len(text).

Starter code

def reverse_slice_segment(text, start, end):
    pass

Public examples

  1. text = "abcdef", start = 1, end = 5gives"aedcbf"
  2. text = "python", start = 3, end = 3gives"python"

Solving it in the practice book needs an active paid plan.

Open it in the practice book
One thought at a time.