Ruslan
Ruslan

Reputation: 43

How can I print a square consisting of numbers from 1 to 9 (from the example) using a 1 line code?

I need to write a code in 1 line, which will print this:

0123456789
1234567890
2345678901
3456789012
4567890123
5678901234
6789012345
7890123456
8901234567
9012345678

I did this:

print([print(i) for i in range(10)])

but this code is completely wrong, the output is:

0
1
2
3
4
5
6
7
8
9
[None, None, None, None, None, None, None, None, None, None]

I think I should use map() and lambda but I have no idea how can i do it, I am just learning...

Upvotes: 1

Views: 362

Answers (1)

Tom Ron
Tom Ron

Reputation: 6181

print("\n".join([("".join(str((i+j)%10) for i in range(10))) for j in range(10)]))

Note that the print function returns None that's the reason you have None printed so many times and you need nested loops to print this 2D array.

Upvotes: 4

Related Questions