0

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]]

2 Answers 2

1

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))
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.