79461266

Date: 2025-02-23 13:14:05
Score: 3.5
Natty:
Report link

As of Python 3.9, string.removeprefix and string.removesuffix are available.

The following code produces '(word)'.

'((word))'.removeprefix('(').removesuffix(')')

It is unclear whether the OP wants a solution that strips exactly-one or all-but-one parens. This solution accomplishes the former, which is a reasonable interpretation based on their ultimate question.

Is there a way to specify that I only want the first and last one removed?

Reasons:
  • Blacklisted phrase (1): Is there a way
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (1):
Posted by: BlackoutJack