import re
list1 = ['apple', 'orange']
text = 'the books are good apple34'
word = re.sub(rf"(?:{'|'.join(map(re.escape, list1))})\d+", 'ball', text)
print(word)
word = re.sub(rf"\b(?:{'|'.join(map(re.escape, list1))})\d+\b", 'ball', text)
print(word)
