In the picture you see the usual multiplication table, which, I think, is well known to everyone.
There is nothing special about it, except that the entire algorithm for its construction is compressed to one standard Python string of 79 characters (see
PEP8 ). Who cares welcome under cat.
To begin with, it is worth answering the question “What is it for?” That appeared in many people. Everything was made up of two factors, firstly, on the insistent recommendation of one good person, I began to study in depth Python, and secondly, I like the concept of the
demoscene . The result was a desire to write (of course, too loudly) something very small (ideally in one line), but visual, using features of Python coding for all of 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.
')
How eight lines turned into one
To begin with, I wrote code that prints multiplication tables, absolutely not caring about compactness:

Listingdef MultiTabl(): tabl = '' for y in range(1,11): for x in range(1,11): tabl += f'{x*y}\t' tabl += f'\n' return tabl
Table values can be generated using generators, and cycles can be left 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
The generator can also be given the 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 retrieved in the first cycle is glued into a line, using the join () string method, use parallel assignment of variables and place the cycle in one line, the code sizes 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 together using join (), thereby getting rid of cycles:
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 and the promised option in one line (from print, of course, not to get rid)
print( ''.join([''.join([f'{x*y}\t' for x in range(1,11)])+'\n' for y in range(1,11)]) )
Of course, the Python gurus will say, “What's wrong with that?”, 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 big article, it would be great if it brings a smile, and just great if it benefits.