ysn-rfd commited on
Commit
78c89f6
1 Parent(s): 19c4ee7

Upload usage-file.py

Browse files
how-to-tokenize-an-text-file-and-save-it/usage-file.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import nltk
2
+ from nltk.tokenize import word_tokenize
3
+
4
+ # load your data
5
+ with open('data.txt', 'r') as file:
6
+ data = file.read()
7
+
8
+ # tokenize the data
9
+ tokens = word_tokenize(data)
10
+
11
+ # save the tokenized data to a file
12
+ with open('tokenized_data.txt', 'w') as file:
13
+ for token in tokens:
14
+ file.write("%s\n" % token)