Created
April 20, 2021 16:36
-
-
Save heisid/b28faeb94b3e168bca51a41813564c6c to your computer and use it in GitHub Desktop.
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 re | |
def tokenize(sentence): | |
delimiter = "(plus|minus|divided by|times|\(|\))" | |
tokens = re.split(delimiter, sentence) | |
# Buang spasi di awal dan akhir | |
tokens = [token.strip() for token in tokens] | |
# Buang yg kosong | |
tokens = list(filter(None, tokens)) | |
return tokens | |
if __name__ == "__main__": | |
test = ["one plus two", | |
"minus (forty-five minus five) divided by five", | |
"six hundred forty-five minus nine hundred"] | |
for sentence in test: | |
tokens = tokenize(sentence) | |
print(tokens) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
kurang kerjaan banget gw ya