I'm using the following single line of python code to print out a specific pattern which I showed at the bottom.
My code:
print(*[a, b, for a in range(5): for b in range(3)], sep='\n')
After executing the above code, I'm getting an invalid syntax error but I could not find any syntax error there.
Error:
Getting error : SyntaxError: invalid syntax
My desired output as follow:
1 1 1 2 1 3 1 4 2 1 2 2 2 3 2 4
How can I print this pattern in a single line of code?
I appreciate your assistance.
print(*[(a, b) for a in range(5) for b in range(3)], sep='\n')Of course that only solves the error, not the formatting - but the string formatting was already explained by others. :)