← Back to challenges

Slicing Strings

PythonHardlanguage_fundamentalsstrings

Instructions

In this challenge you are given a string and a slice made from that string. Make a function that returns an expression that can be used to make that slice. Your answer must contain only the minimum number of keystrokes needed to make the slice.

Examples

slicer("abcd", "b") ➞ "[1]"

slicer("abcdefg", "cb") ➞ "[2:0:-1]"

slicer("abcdefg", "be") ➞ "[1::3]"

slicer("abcdefgh", "bdf") ➞ "[1:6:2]"

Notes

  • Test cases are slices that can be made with the [start:end:step] type expression.
  • The strings are composed of unique characters (no repeats).
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.