我这里有一段我认为非常草率的代码:
industry = []
headquarters = []
specialties = []
totalEmployeeCount = []
growth6Mth = []
website = []
for i in cvs_data:
j = ci_data[0]
for j in ci_data:
if i['companyName'] == j['name']:
industry.append(Cell(row = cvs_data.index(i)+2, col = 6,
value = j['industry']))
headquarters.append(Cell(row = cvs_data.index(i)+2, col = 8,
value = j['headquarters']))
specialties.append(Cell(row = cvs_data.index(i)+2, col = 9,
value = j['specialties']))
totalEmployeeCount.append(Cell(row = cvs_data.index(i)+2, col = 10,
value = j['totalEmployeeCount']))
growth6Mth.append(Cell(row = cvs_data.index(i)+2, col = 11,
value = j['growth6Mth']))
website.append(Cell(row = cvs_data.index(i)+2, col = 14,
value = j['website']))
cvs.update_cells(industry)
cvs.update_cells(headquarters)
cvs.update_cells(specialties)
cvs.update_cells(totalEmployeeCount)
cvs.update_cells(growth6Mth)
cvs.update_cells(website)
其中,cvs_数据是用于索引的DICT列表。实际的gspread工作表(cvs)将使用ci_数据(另一个DICT列表)中的值进行更新
我猜我的搜索也会更好
是否可以将所有这些值(即行业、总部等)附加到一个字典而不是单个列表中,然后在该字典上调用update_cells()
如果您的目标是拥有一个
update_cells()
,那么您应该能够使用:您的单元格对象看起来都有行和列数据,因此它们不需要位于单独的列表中
我不认为我见过任何从dict到google表单的东西,但另一种方法(关键是行业、总部等,而值是单元格列表)是:
对于您的搜索,将
ci_data
从一个dict列表重新组织为一个dict可能会有所帮助。您可以将键设置为名称,而值设置为dicts:这样,代码中就不会有循环嵌套:
相关问题 更多 >
编程相关推荐