0
我想實現simple_tokenize使用字典作爲我以前的代碼的輸出,但我收到一條錯誤消息。對以下代碼的任何幫助將不勝感激。我使用Python 2.7 Jupyterpython的Jupyter字符串標記化
import csv
reader = csv.reader(open('data.csv'))
dictionary = {}
for row in reader:
key = row[0]
dictionary[key] = row[1:]
print dictionary
上述工作得很好,但問題是有以下幾點:
import re
words = dictionary
split_regex = r'\W+'
def simple_tokenize(string):
for i in rows:
word = words.split
#pass
print word
我得到這個錯誤:
NameError Traceback (most recent call last)
<ipython-input-2-0d0e05fb1556> in <module>()
1 import re
2
----> 3 words = dictionary
4 split_regex = r'\W+'
5
NameError: name 'dictionary' is not defined