[英]Python text mining
I have a function get_numbers('X') that runs a Bing search to find a contact number for 'X', ie get_numbers('Google') would return a customer service contact number.我有一个函数 get_numbers('X') 运行 Bing 搜索以查找 'X' 的联系号码,即 get_numbers('Google') 将返回客户服务联系号码。 I want to extend the search by running Bing search on different forms of the company name.
我想通过对不同形式的公司名称运行 Bing 搜索来扩展搜索。 And then run a for loop to run get_numbers on all the versions of the name.
然后运行 for 循环以在名称的所有版本上运行 get_numbers。
def company_names(company):
etc =['','ltd','plc', 'inc']
names = [ '{} {}'.format(company,i) for i in etc ]
return names
def get_more_numbers(company):
company = company_names(company)
for i in company:
name = company[i]
get_numbers(name)
I'm getting the error:我收到错误:
File "<ipython-input-22-716ce1744cc0>", line 5, in get_more_numbers
name = company[i]
TypeError: list indices must be integers, not str
You cannot have string as indices.您不能将字符串作为索引。 You are iterating using a for each of string.
您正在对每个字符串使用 a 进行迭代。
i
will contain the name. i
将包含名称。 Not the index.不是指数。 You can remove this line.
您可以删除此行。
name = company[i]
And replace next line with get_numbers(i)
并用
get_numbers(i)
替换下一行
Replace代替
for i in company:
name = company[i]
get_numbers(name)
by:经过:
for name in company:
get_numbers(name)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.