easy +10 pts

Normalize quotes

Replace typographic quotes with straight ones in a given string.

Implement a function `normalize_quotes(s: str) -> str` that returns a new string where every typographic quote character is replaced by the corresponding straight ASCII quote. Specifically: - Replace the left double quotation mark `“` (U+201C) and right double quotation mark `”` (U+201D) with the straight double quote `"`. - Replace the left single quotation mark `‘` (U+2018) and right single quotation mark `’` (U+2019) with the apostrophe `'`. - Do not change any other characters. The function should preserve the order of all other characters and work for any input string, including empty strings and strings with no quotes.

Constraints

Input is a string of length 0 to 100,000 characters. The function should run in O(n) time and O(n) space, where n is the length of the string.

Example

>>> normalize_quotes('He said, “Hello!”')
'He said, "Hello!"'

>>> normalize_quotes('It’s a test')
"It's a test"

>>> normalize_quotes('“Quoted” and ‘single’')
'"Quoted" and \'single\''
10 points ~12 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Create a translation table mapping the four Unicode characters to their ASCII equivalents.
Use the `str.translate` method with a dictionary or `str.maketrans`.
Remember to escape the double quote in the replacement string if you use a regular string literal.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.