This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
# In [1]: string.punctuation | |
# Out[1]: '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' | |
# In [2]: string.uppercase | |
# Out[2]: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
# In [3]: " " * len(string.punctuation) + string.lowercase | |
# Out[3]: ' abcdefghijklmnopqrstuvwxyz' | |
# translation table maps upper case to lower case and punctuation to spaces | |
translation_table = string.maketrans(string.punctuation+string.uppercase, | |
" " * len(string.punctuation) + string.lowercase) | |
line = "" | |
line = line.translate(translation_table) | |
# In [4]: line | |
# Out[4]: 'foo bar bizz' | |
word_list = line.split() | |
# In [5]: word_list | |
# Out[5]: ['foo', 'bar', 'bizz'] |