easy +10 pts

Remove punctuation

Strip all ASCII punctuation from a string while preserving letters, digits, and whitespace.

Write a function `remove_punctuation(text: str) -> str` that takes a string `text` and returns a new string with all ASCII punctuation characters removed. 'ASCII punctuation' means any character for which `string.punctuation` contains that character. All other characters (letters, digits, whitespace, and other non-ASCII characters like 'é' or '中') must remain unchanged. For an empty string, return an empty string.

Constraints

0 <= len(text) <= 10^5. The function must run in O(n) time where n is the length of the input. Only the standard library is allowed.

Example

>>> remove_punctuation('Hello, world!')
'Hello world'
>>> remove_punctuation('No punctuation here')
'No punctuation here'
>>> remove_punctuation('...python...')
'python'
10 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use Python's `string` module to get the set of punctuation characters.
A list comprehension with a condition can filter quickly.
Join the filtered characters with `''.join(...)`.
Remember to preserve all other characters, including whitespace and non-ASCII.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.