I used this example here if/else in a list comprehension for list comprehension with if-else to create a constraint for the sum .
This is the piece of code that triggers the error
for j in range(1, m+1):
solver.Add(solver.Sum([0 if c[i][j]==0 else x[i, j] for i in range(1, n+1)]) <= 1)
x is a dict defined earlier and c[i][j] is a boolean that is 1 when (i,j) is in the permitted. But when (i,j) is in permitted x[i,j] holds a variable in ortools . So what I am saying is that I want for this particular j to sum x[i,j]'s , if x[i,j] exists then ok if it does not then just add 0 .
c = [[0]*(m+1)]*(n+1)
for (i,j) in permitted:
c[i][j]=1
x = {}
for (i,j) in permittted:
x[i, j] = solver.IntVar(0, 1, '')