Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-400

Punctuation Run Collapse

Problem

Collapse runs of the same punctuation character into a single character, for example "!!" becomes "!".

Given text, return the collapsed text.

Hint

Skip a character when it repeats the previous punctuation character.

Test cases

case 1
in: ["Wow!!!"]
expected: "Wow!"
case 2
in: ["a...b"]
expected: "a.b"
case 3
in: ["no punctuation"]
expected: "no punctuation"
Starter codePython
def punctuation_run_collapse(text):
    # Your code here
    pass

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