小编len*_*eth的帖子

从列表中填充字典

我有一个字符串列表(来自.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 dictionary list python-3.x

5
推荐指数
3
解决办法
1012
查看次数

Python 3.4中的BeautifulSoup无效语法(在2to3.py之后)

我想在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)

有任何想法吗?

python beautifulsoup python-3.x python-3.4

3
推荐指数
1
解决办法
8590
查看次数