摘要:在这里我将搜集一些神奇的Python代码,希望能不断更新。。。1. List Comprehensions使用list comprehension可以杜绝掉50%以上的for循环,后者的效率极其低下(可以看看C源码的实现),而且不够紧凑。(1) Python官方的例子:>>> [(x, y) for x in [1,2,3] for y in [3,1,4] if x !=y]运行结果得到:[(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)](2) list的反转:lis[::-1](3) 找n以内的质数:>&
阅读全文
posted @ 2014-01-10 01:26
浙公网安备 33010602011771号