Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-236

SentencePiece Whitespace Marker

Problem

Apply SentencePiece-style whitespace marking to text. Prepend the marker '▁' (U+2581) and replace every space with the same marker.

Return the transformed string.

Hint

Prepend once, then replace; an empty string becomes the marker alone.

Test cases

case 1
in: ["hello world"]
expected: "▁hello▁world"
case 2
in: [""]
expected: "▁"
case 3
in: ["a b"]
expected: "▁a▁▁b"
case 4
in: [" leading"]
expected: "▁▁leading"
case 5
in: ["no"]
expected: "▁no"
Starter codePython
def sentencepiece_whitespace(text):
    # Your code here
    pass

5 test cases · run your code against them in the editor