【发布时间】:2020-03-22 03:46:05
【问题描述】:
嗨,我是练习列表,我得到 TypeError: can only concatenate list (not "str") to list
如何解决?
我的代码
from bs4 import BeautifulSoup
tag_list= ['Flying','Flight']
links = ['https://goo.gl/'+x for x in tag_list+'/text']
print links
它会给我错误,但如果我将代码编辑为此,它会起作用。
tag_list= ['Flying','Flight']
links = ['https://goo.gl/'+x for x in tag_list]
print links
请问如何解决links = ['https://goo.gl/'+x for x in tag_list+'/text']
【问题讨论】:
-
期望的输出是什么?
-
你想通过
tag_list + 'text'得到什么?['Flyingtext','Flighttext']? -
您可以连接两个字符串或两个列表,即。
tag_list + ['text'] -
我想要输出是 ['goo.gl/Flying/text'] 因为我什么 res = requests.get(links)
-
你可以做
['https://goo.gl/{}/text'.format(x) for x in tag_list]
标签: python python-2.7