python有趣的一行代码
1.程序员式表白
print'\n'.join([''.join([('AndyLove'[(x-y)%8]if((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3<=0 else' ')for x in range(-30,30)])for y in range(15,-15,-1)])
2.一行显示乘法表
print('\n'.join([' '.join(['%s*%s=%-2s' % (y,x,x*y) for y in range(1,x+1)]) for x in range(1,10)]))
3.一行显示迷宫
print(''.join(__import__('random').choice('\u2571\u2572') for i in range(50*24)))
4.一行代码输出Mandelbrot图像
print('\n'.join([''.join(['*'if abs((lambda a:lambda z,c,n:a(a,z,c,n))(lambda s,z,c,n:z if n==0else s(s,z*z+c,c,n-1))(0,0.02*x+0.05j*y,40))<2else' 'for x in range(-80,20)]) for y in range(-20,20)]))
5.一行代码计算出1-100之间的素数
print(' '.join([str(item) for item in filter(lambda x: all(map(lambda p: x % p!= 0, range(2, x))), range(2, 101))]))
6.一行代码输出前100项斐波那契数列的值
print([x[0] for x in [ (a[i][0], a.append((a[i][1], a[i][0]+a[i][1]))) for a in ([[1,1]], ) for i in range(100) ]])
7.一行代码自动看漫画
import antigravity
8.无限字符动画
python -c "while 1:import random;print(random.choice('^_^'), end='')"