PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
# Use regular expressions to remove the letter "t" from the end of each word w in a string ,unless the word is "it" or "at".
from re import sub
test = "An adult wombat at the river belt plays it safe."
print(test)
# without regexp
list_comp = " ".join(word if word in ('it', 'at') or not word.endswith('t') else word[:-1] for word in test.split())
print(list_comp)
regexp = sub(r'(?<!\b[ia])t\b', '', test)
print(regexp)
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run