# Single row multiplication table In the picture you see the usual multiplication table, which, I think, is familiar to everyone.
There is nothing special about it, except that the entire algorithm for constructing it is compressed to one standard Python string of 79 characters (see PEP8 ). Who cares, welcome to cat.

To begin with, it is worth answering the question that arose among many, “Why is this?”. It all came together from two factors, firstly, on the strong recommendation of one good person, I took up an in-depth study of Python, and secondly, I like the concept of the demoscene. The result was a desire to write (of course too loudly said) something very small (ideally in one line), but visual, using the features of Python coding for all this. I decided to display the multiplication table.

It is worth noting that I am writing in Python3.7. Versions under 3.6 will not work due to the lack of support for f-lines, and as a result, the working script will exceed 79 characters in length.

#### How eight lines turned into one

To begin with, I wrote code that displays the multiplication table, absolutely not caring about compactness: Listing
``````def MultiTabl():
tabl = ''
for y in range(1,11):
for x in range(1,11):
tabl += f'{x*y}\t'
tabl += f'\n'
return tabl
``````

You can generate table values ​​using generators, and leave the loops to unpack lists. The disadvantage of this approach was a larger number of lines: Listing
``````def MultiTabl():
nums = [[x*y for x in range(1,11)] for y in range(1,11)]
tabl = ''
for line in nums:
for item in line:
tabl += f'{item}\t'
tabl += f'\n'
return tabl
``````

You can also give the generator an arrangement of Tabs ('\ t') using f-lines:

``````nums = [[f'{x*y}\t' for x in range(1,11)] for y in range(1,11)]
``````

If the list extracted in the first loop is glued into a string using the string join () method, using the parallel assignment of variables and placing the loop on one line, the code size will be significantly reduced: Listing
``````def MultiTabl():
nums, tabl = [[f'{x*y}\t' for x in range(1,11)] for y in range(1,11)], ''
for line in nums: tabl += ''.join(line) + '\n'
return tabl
``````

And if you add join () and '\ n' to the generator:

``````def MultiTabl():
nums, tabl = [''.join([f'{x*y}\t' for x in range(1,11)])+'\n' for y in range(1,11)], ''
for line in nums: tabl += line
return tabl
``````

Now we have a list of strings at our disposal, and it can also be glued using join (), thereby getting rid of loops:
``````def MultiTabl():
tabl = ''.join([''.join([f'{x*y}\t' for x in range(1,11)])+'\n' for y in range(1,11)])
return tabl
``````

Well, the promised option in one line (of course, you can’t get rid of print)

``````print(
''.join([''.join([f'{x*y}\t' for x in range(1,11)])+'\n' for y in range(1,11)])
)
``````

Of course, Python gurus will say, “What is it?”, But it’s worth noting that this approach is not obvious to beginners.

You should not take this opus too seriously, I wrote it as a warm-up before a large article, it will be great if it brings a smile, and just fine if it benefits.