问题
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