108k views
4 votes
A common preprocessing step in many natural language processing tasks is text normalization, wherein words are converted to lowercase, extraneous whitespace is removed, etc. Write a function normalize(text) that returns a normalized version of the input string, in which all words have been

converted to lowercase and are separated by a single space. No leading or trailing whitespace should be present in the output.

>>> normalize("This is an example.")
'this is an example.'
>>> normalize(" EXTRA SPACE ")
'extra space'

User Shaolo
by
5.0k points

1 Answer

4 votes

Answer:

def normalize(text):

text = text.lower()

text = text.split()

return text

Step-by-step explanation:

The functiinfunction is provided with an input text when called upon, then it changes every character in the text into lower case and split each word with a space.

User Matphy
by
5.4k points