Back to questions
JuniorTheoryCommon
What does this program print?
text = "Good film. Good, good cast!"
tokens = text.lower().split()
print(len(tokens), len(set(tokens)))5 4
- Expecting
5 3:split()cuts only at whitespace, sofilm.andgood,keep their punctuation and differ fromgood. - Expecting
5 5:lower()runs beforesplit(), so the firstGoodbecomesgoodand matches the othergood.
- How would you clean the text so that every form of
goodbecomes one token? - Why can deleting punctuation instead of replacing it with a space merge two words?