Reputation: 1
I have tried this approach:
print((i, j) for i in [0,x] for j in [0, y] if (i+j)!=n)
where x
,y
,n
are integers.
Formatting the output in python from [(1,2) , (2,3)]
to [[1,2], [2,3]]
Upvotes: 0
Views: 65
Reputation: 160367
And you're getting output of <generator object at ...>
, because that's the only argument you supply the generator expression. Either turn it into a list comp and unpack it to print:
print(*[(i, j) for i in [0,x] for j in [0, y] if (i+j)!=n])
or create the generator first, iterate through it and print out its results.
Upvotes: 0
Reputation: 14509
Simply change (
to [
(and wrap it in a list constructor to print the list, rather than the generator).
print(list([i, j] for i in [0,x] for j in [0, y] if (i+j)!=n))
Upvotes: 1