Python combination with criteria and output in excel

半腔热情 提交于 2019-12-11 08:37:41

问题


I have two lists and I want a combination which satisfies a particular condition for which I wrote the following program and printed the result in 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()

Debug console shows

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

Why is this not working?

Intended Output The combination (x,y) x from a and y from b such that combination (x,y) in c is not included.

来源:https://stackoverflow.com/questions/51898765/python-combination-with-criteria-and-output-in-excel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!