Spy Message Decoder

Python for AIMedium+10 XP+10

Spy Message Decoder

A spy hides a code word inside an ordinary sentence. A second list says which positions to read, in order.

Task: write decode(message, positions) that returns a new string made from the letter at each position in positions, in the order given.

  • Positions can be negative, which counts from the end, just like a list.
  • A position can appear more than once.
  • Every position is valid for the message. Spaces count as positions too.
  • If positions is empty, return "".

Examples

message = "the owl hoots"
positions = [4, 0, -1]
returns 'ots'
message = "python"
positions = [0, 1, 0, 1]
returns 'pypy'

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run