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