Aan de slagGa gratis aan de slag

Basic list comprehensions

For this task, you will have to create a bag-of-words representation of the spam email stored in the spam variable (you can explore the content using the shell). Recall that bag-of-words is simply a counter of unique words in a given text. This representation can be further used for text classification, e.g. for spam detection (given enough training examples).

We created a small auxiliary function create_word_list() to help you split a string into words, e.g. applying it to 'To infinity... and beyond!' will return ['To', 'infinity', 'and', 'beyond'].

Deze oefening maakt deel uit van de cursus

Practicing Coding Interview Questions in Python

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Convert the text to lower case and create a word list
words = ____
Code bewerken en uitvoeren