pythonic

Pythonic = 大道至简

1. 列表迭代

for element in mylist:
    do_something(element)
2. 函数返回多值
def foo():
    return a, b
a, b = foo()
3. 挺长的九九乘法
print "".join([('%s*%s=%s%s' % (y,x,x*y,'\n' if x==y else '\t')) for x in range(1,10) for y in range(1,10) if x >= y])
4. 素数
print reduce(lambda l,y:not 0 in map(lambda x:y % x, l) and l+[y] or l,xrange(2,1000), [] )

reduce函数见这边

参考:

blog.csdn.net/lanphaday/article/details/2762251
apt-blog.net/what_is_pythonic


你可能感兴趣的:(pythonic)