Clear Digits
You are given a string s
.
Your task is to remove all digits by doing this operation repeatedly:
- Delete the first digit and the closest non-digit character to its left.
Return the resulting string after removing all digits.
def clearDigits(self, s: str) -> str:
while any(char.isdigit() for char in s) and any(char.isalpha() for char in s):
for i in range(len(s)):
j=i-1
if s[i].isdigit():
s=s[:i] + s[i+1:]
s=s[:j] + s[j+1:]
break
return s
while the there is a Digit and a Alphabet in the string keep doing these actions:
1. remove the the first digit
2. remove the closest alphabet to its left