I'm working on a project that involves parsing pages of text. I've written the following function to remove certain punctuation from a word and convert it to lowercase:
def format_word(word):
return word.replace('.', '').replace(',', '').replace('\"', '').lower()
Is there any way to combine all of the calls to .replace() into one? This looks rather ugly the way it is! The only way I can think of doing it is as follows:
def format_word(word):
for punct in '.,\"':
word.replace(punct, '')
return word.lower()