On 2020-08-11 20:43, Dennis Lee Bieber wrote:
On Tue, 11 Aug 2020 14:17:39 -0400, Joel Goldstick
<joel.goldst...@gmail.com> declaimed the following:

[snip]

Warning -- it will fail if the input is just a pair of quotes or pair of
apostrophes -- improvement is

while s and s[0] in ['"', "'"]:
...     if s[0] == s[-1]:
...             s = s[1:-1]

If the 'if' condition is False, then 's' will remain unchanged, and it will loop forever.

I would suggest:

>>> while s[ : 1] in {'"', "'"} and s[ : 1] == s[-1 : ]:
...     s = s[1 : -1]
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to