Differences between revisions 1 and 12 (spanning 11 versions)
Revision 1 as of 2005-02-24 12:01:02
Size: 212
Editor: ZoomQuiet
Comment:
Revision 12 as of 2009-12-25 07:08:34
Size: 973
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 6: Line 6:
::-- ZoomQuiet [[[DateTime(2005-02-24T12:01:02Z)]]]
[[TableOfContents]]
::-- ZoomQuiet [<<DateTime(2005-02-24T12:01:02Z)>>]
<<TableOfContents>>
Line 10: Line 10:
 * [[http://blog.csdn.net/lanphaday/archive/2008/08/03/2762251.aspx|Pythonic到底是什么玩意儿?]] - 赖勇浩(恋花蝶)的博客 - CSDNBlog
 * [[http://blog.donews.com/limodou/archive/2005/08/07/498175.aspx|What is Pythonic?]] - limodou的学习记录 - DonewsBlog

= 直觉 =

 * [[PyCNmail:2005-June/011545.html|急:文本文件中有选择的读取并按照有关格式存储数据的问题]]
  * 这样的问题,其实是Py 最擅长的!当年多个国家的人类基因确认工程中,不同格式的DNA数据的自动同步匹配合成就是Py 干的!
  * /EasyThinkAndDoneIt -- 如何简要的完成任务

== 内省 ==
 * PyBatteriesIncluded -- Python哲学-内省

== 素数 ==
<<Include(PyPrimeNumberGenerator)>>

Pythonic -- 蟒样 坚韧,灵活,柔韧......

::-- ZoomQuiet [2005-02-24 12:01:02]

汇集 Python 味道的技巧,思路,方式....

直觉

内省

素数

  • 单行程序 扫描素数!

    from math import sqrt
    # 求N 以内的素数...
    from math import sqrt
    N = 100
    [ p for p in   range(2, N) if 0 not in [ p% d for d in range(2, int(sqrt(p))+1)] ]
    ^ ^  ^     ^               ^    ^      ^  ^              ^            ^      ^
    | |  |     |               |    |      |  |              |            |      +- 弥补
    | |  |     |               |    |      |  |              |            +- 通过平方精简尝试
    | |  |     |               |    |      |  |              +- 组织所有 2~p 之间可能为公因子的数列
    | |  |     |               |    |      |  +- 求余,尝试整除
    | |  |     |               |    |      +- 列表运算,直接将以上计算结果组成数组 返回 
    | |  |     |               |    +- 余数0 不在求余结果列表中
    | |  |     |               +- 即2~p 都不能整除 p 的p
    | |  |     +- 提取运算
    | |  +- for..in 循环取数,从2~p 的连续数组中
    | +- 素数!
    +- 列表计算组织所有结果为数组返回!
    # 优化::N > 10000 时可以使用 xrange() 进行优化生成数列

   1 # SOP 式的排版:
   2 [ p for p in range(2, N) 
   3     if 0 not in [ p%d 
   4         for d in range(2, int(sqrt(p))+1)
   5                 ] 
   6 ]

PythonIc (last edited 2009-12-25 07:08:34 by localhost)