Generating a line of code in all the elements of the multiplication table

This example demonstrates a nested loop for circulation list for formula, as follows:

multi_table = [ i*j for i in range(1,10) for j in range(i,10)]

Print results are as follows:

[1, 2, 3, 4, 5, 6, 7, 8, 9, 4, 6, 8, 10, 12, 14, 16, 18, 9, 12, 15, 18, 21, 24, 27, 16, 20, 24, 28, 32, 36, 25, 30, 35, 40, 45, 36, 42, 48, 54, 49, 56, 63, 64, 72, 81]
[Finished in 0.6s]
Published 170 original articles · won praise 9 · views 4545

Guess you like

Origin blog.csdn.net/weixin_41855010/article/details/104482569