import re
list_words = ["cat", "dog", "animals", "adam"]
text = "I have a lot of animals,       cat and a     dog"
pattern = r",*(\s*\b(?:{}))\b".format("|".join(list_words))
print( re.sub(pattern, r",\1", text) )
