{"id":1180,"date":"2013-04-24T22:49:24","date_gmt":"2013-04-25T02:49:24","guid":{"rendered":"http:\/\/yuguangzhang.com\/blog\/?p=1180"},"modified":"2015-11-19T13:48:51","modified_gmt":"2015-11-19T18:48:51","slug":"calculating-prime-numbers-in-python","status":"publish","type":"post","link":"http:\/\/yuguangzhang.com\/blog\/calculating-prime-numbers-in-python\/","title":{"rendered":"Calculating Prime Numbers in Python"},"content":{"rendered":"<p>The repository of <a href=\"http:\/\/pythonfiddle.com\/fiddles\/\">Python code snippets<\/a> on <a href=\"http:\/\/pythonfiddle.com\/\">Python Fiddle<\/a>\u00a0now has 742 posted and counting. Among them, there are several for listing prime numbers. The naive approach by factoring definitely isn&#8217;t efficient:<\/p>\n<p><iframe loading=\"lazy\" style=\"width: 100%; height: 300px;\" src=\"http:\/\/pythonfiddle.com\/calculate-prime-numbers\/embedded\/\" height=\"240\" width=\"320\"><\/iframe><\/p>\n<p>Another approach also contains the hidden double for loop:<br \/>\n<iframe loading=\"lazy\" style=\"width: 100%; height: 300px;\" src=\"http:\/\/pythonfiddle.com\/prime-number-generator\/embedded\/\" height=\"240\" width=\"320\"><\/iframe><\/p>\n<p>Way to go with this one, packing a little program into the regular expression:<br \/>\n<iframe loading=\"lazy\" style=\"width: 100%; height: 300px;\" src=\"http:\/\/pythonfiddle.com\/identifying-primes-regular-expressions-and-python\/embedded\/\" height=\"240\" width=\"320\"><\/iframe><\/p>\n<p>If I were to do it, I&#8217;d implement it with <a href=\"http:\/\/en.wikipedia.org\/wiki\/Sieve_of_Eratosthenes\">Eratosthenes&#8217;s algorithm<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The repository of Python code snippets on Python Fiddle\u00a0now has 742 posted and counting. Among them, there are several for listing prime numbers. The naive approach by factoring definitely isn&#8217;t efficient: Another approach also contains the hidden double for loop: Way to go with this one, packing a little program into the regular expression: If [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[146],"tags":[190,189,22],"class_list":["post-1180","post","type-post","status-publish","format-standard","hentry","category-pythonfiddle","tag-prime","tag-prime-number-generator","tag-python"],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/yuguangzhang.com\/blog\/wp-json\/wp\/v2\/posts\/1180","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/yuguangzhang.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/yuguangzhang.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/yuguangzhang.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/yuguangzhang.com\/blog\/wp-json\/wp\/v2\/comments?post=1180"}],"version-history":[{"count":1,"href":"http:\/\/yuguangzhang.com\/blog\/wp-json\/wp\/v2\/posts\/1180\/revisions"}],"predecessor-version":[{"id":1440,"href":"http:\/\/yuguangzhang.com\/blog\/wp-json\/wp\/v2\/posts\/1180\/revisions\/1440"}],"wp:attachment":[{"href":"http:\/\/yuguangzhang.com\/blog\/wp-json\/wp\/v2\/media?parent=1180"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/yuguangzhang.com\/blog\/wp-json\/wp\/v2\/categories?post=1180"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/yuguangzhang.com\/blog\/wp-json\/wp\/v2\/tags?post=1180"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}