Skip to content

Instantly share code, notes, and snippets.

@heisid
Created April 20, 2021 16:36
Show Gist options
  • Save heisid/b28faeb94b3e168bca51a41813564c6c to your computer and use it in GitHub Desktop.
Save heisid/b28faeb94b3e168bca51a41813564c6c to your computer and use it in GitHub Desktop.
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)
@heisid
Copy link
Author

heisid commented Apr 20, 2021

kurang kerjaan banget gw ya

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment