Return the tokens of a sentence including punctuation. >>> tokenize('Bob dropped the apple. Where is the apple?') ['Bob', 'dropped', 'the', 'apple', '.', 'Where', 'is', 'the', 'apple', '?']
(sent)
| 38 | |
| 39 | |
| 40 | def tokenize(sent): |
| 41 | '''Return the tokens of a sentence including punctuation. |
| 42 | |
| 43 | >>> tokenize('Bob dropped the apple. Where is the apple?') |
| 44 | ['Bob', 'dropped', 'the', 'apple', '.', 'Where', 'is', 'the', 'apple', '?'] |
| 45 | ''' |
| 46 | return [x.strip() for x in re.split('(\W+?)', sent) if x.strip()] |
| 47 | |
| 48 | |
| 49 |