Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-133

Contraction Splitting

Problem

Split an English contraction into its base and suffix. Handle the irregular forms can't, won't, and shan't explicitly.

Otherwise split off the longest matching suffix from n't, 're, 've, 'll, 'd, 'm, and 's when a non-empty base remains, and return the word unchanged when no suffix matches.

Hint

Check the irregular map before the suffix loop.

Test cases

case 1
in: ["don't"]
expected: ["do","n't"]
case 2
in: ["can't"]
expected: ["ca","n't"]
case 3
in: ["we're"]
expected: ["we","'re"]
case 4
in: ["dogs"]
expected: ["dogs"]
case 5
in: ["won't"]
expected: ["wo","n't"]
Starter codePython
def contraction_split(word):
    # Your code here
    pass

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