Python与条件组合和Excel中的输出

时间:2018-08-17 15:37:23

标签: excel python-3.x xlsxwriter

我有两个列表,我想要一个满足特定条件的组合,为此我编写了以下程序并将结果打印在excel中:

a = [1.01, 5.84, 13.86, 14.72, -12.45]

b = [6.42,5.67,12.51,0,7.23,8.45,9.11,18.24]

combination1 = [(x,y) for x in a 

                      for y in b]

c = [(1.01,18.24), (13.86,0), (5.84,0)]

combined_list = [combination1 and combination1 != c]

import xlsxwriter
workbook = xlsxwriter.Workbook('jam.xlsx')
worksheet = workbook.add_worksheet()

row = 0

for group in (combined_list):
    for col in range(2):
      worksheet.write (row, col, group[col])
    row += 1
workbook.close()

调试控制台显示

worksheet.write (row, col, group[col])
TypeError: 'bool' object is not subscriptable

为什么这不起作用?

预期输出 来自a的(x,y)x和来自b的y,因此不包括c中的组合(x,y)。

0 个答案:

没有答案