When I use "\n"
in my print
function it gives me a syntax error in the following code
from itertools import combinations
a=[comb for comb in combinations(range(1,96+1),7) if sum(comb) == 42]
print (a "\n")
Is there any way to add new line in each combination?
The print
function already adds a newline for you, so if you just want to print followed by a newline, do (parens mandatory since this is Python 3):
print(a)
If the goal is to print the elements of a
each separated by newlines, you can either loop explicitly:
for x in a:
print(x)
or abuse star unpacking to do it as a single statement, using sep
to split outputs to different lines:
print(*a, sep="\n")
If you want a blank line between outputs, not just a line break, add end="\n\n"
to the first two, or change sep
to sep="\n\n"
for the final option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With