我有一个字符串列表(来自.tt文件),如下所示:
list1 = ['have\tVERB', 'and\tCONJ', ..., 'tree\tNOUN', 'go\tVERB']
Run Code Online (Sandbox Code Playgroud)
我想把它变成一个看起来像的字典:
dict1 = { 'have':'VERB', 'and':'CONJ', 'tree':'NOUN', 'go':'VERB' }
Run Code Online (Sandbox Code Playgroud)
我在考虑替代,但它效果不好.有没有办法将标签字符串标记'\t'为分隔符?
我想在Python 3.4中安装Beautiful Soup 4.我从命令行安装它(得到了无效的语法错误,因为我没有转换它),运行2to3.py转换脚本到bs4现在我得到一个新的无效语法错误.
>>> from bs4 import BeautifulSoup
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
from bs4 import BeautifulSoup
File "C:\Python34\bs4\__init__.py", line 30, in <module>
from .builder import builder_registry, ParserRejectedMarkup
File "C:\Python34\bs4\builder\__init__.py", line 4, in <module>
from bs4.element import (
File "C:\Python34\bs4\element.py", line 1213
print 'Running CSS selector "%s"' % selector
^
SyntaxError: Missing parentheses in call to 'print'
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?