python冲刺(5)列表声称式

      

        [x * x for x in range(1, 11)]   =》[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]

                          这种写法就是python特有的列表生成式。利用列表生成式,可以以非常简洁的代码生成list。

                         eg:

                             [1x2, 3x4, 5x6, 7x8, ..., 99x100] =>

          print [x*(x+1) for x in range(1,100,2)]

                          print [m*100 + n*10 +b for m in range(1,10) for n in range(0,10) for b in range(1,10) if m==b]

生成对称的3位数。  

[101, 111, 121, 131。。。。
原文地址:https://www.cnblogs.com/simplife-xd/p/8044997.html