{"id":1411,"date":"2019-08-26T22:30:05","date_gmt":"2019-08-26T13:30:05","guid":{"rendered":"https:\/\/blog.minatoproject.com\/?p=1411"},"modified":"2020-02-07T22:25:33","modified_gmt":"2020-02-07T13:25:33","slug":"%e3%80%90python%e3%80%91%e7%b5%90%e5%b1%80%e3%80%81%e3%83%aa%e3%82%b9%e3%83%88%e5%86%85%e5%8c%85%e8%a1%a8%e8%a8%98%e3%81%af%e9%80%9f%e3%81%84%e3%81%ae%e3%81%8b%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/blog.minatoproject.com\/?p=1411","title":{"rendered":"\u3010Python\u3011\u7d50\u5c40\u3001\u30ea\u30b9\u30c8\u5185\u5305\u8868\u8a18\u306f\u901f\u3044\u306e\u304b\uff1f"},"content":{"rendered":"<div class=\"veu_autoEyeCatchBox\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/blog.minatoproject.com\/wp-content\/uploads\/2019\/08\/20190826_eyecatch-1024x576.png\" class=\"attachment-large size-large wp-post-image\" alt=\"\" srcset=\"https:\/\/blog.minatoproject.com\/wp-content\/uploads\/2019\/08\/20190826_eyecatch-1024x576.png 1024w, https:\/\/blog.minatoproject.com\/wp-content\/uploads\/2019\/08\/20190826_eyecatch-300x169.png 300w, https:\/\/blog.minatoproject.com\/wp-content\/uploads\/2019\/08\/20190826_eyecatch-768x432.png 768w, https:\/\/blog.minatoproject.com\/wp-content\/uploads\/2019\/08\/20190826_eyecatch-320x180.png 320w, https:\/\/blog.minatoproject.com\/wp-content\/uploads\/2019\/08\/20190826_eyecatch.png 1280w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/div>\n<p>Python\u3067\u306f\u4e00\u822c\u7684\u306b\u5358\u7d14\u306a\u30ea\u30b9\u30c8\u8ffd\u52a0\u306e\u30eb\u30fc\u30d7\u3092\u56de\u3059\u5834\u5408\u3001for\u3067\u56f2\u3046\u3088\u308a\u3082\u30ea\u30b9\u30c8\u5185\u5305\u8868\u8a18\u3068\u3044\u3046\u306e\u3092\u4f7f\u3063\u305f\u65b9\u304c\u6700\u5927\u30675\u500d\u7a0b\u5ea6\u9ad8\u901f\u3067\u3042\u308b\u3068\u3044\u3046\u4fd7\u8aac\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4f8b\u3048\u3070\u5358\u7d14\u306afor\u30eb\u30fc\u30d7\u3067\u56de\u3059\u5834\u5408\u3001<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>l = []\nfor i in range(100):\n    l.append(i)<\/code><\/pre><\/div>\n\n\n\n<p>\u3068\u304b\u3084\u308a\u307e\u3059\u304c\u3001\u3053\u308c\u3068\u540c\u3058\u3082\u306e\u3092\u30ea\u30b9\u30c8\u5185\u5305\u8868\u8a18\u3067\u66f8\u304f\u3068\u3001<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>l = [i for i in range(100)]<\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u53ef\u8aad\u6027\u306f\u3055\u3066\u304a\u3044\u3066\u3053\u306e\u4fd7\u8aac\u3001\u5b9f\u969b\u30ea\u30b9\u30c8\u5185\u5305\u8868\u8a18\u3092\u591a\u7528\u3057\u3066\u3044\u305f\u5272\u306b\u306f\u3042\u307e\u308a\u5b9f\u8a3c\u3057\u305f\u3053\u3068\u304c\u306a\u304f\u3001\u7136\u3089\u30701\u6b21\u30bd\u30fc\u30b9\u3092\u8fbf\u308b\u3079\u304d\u306a\u306e\u3067\u3057\u3087\u3046\u3051\u308c\u3069\u305d\u308c\u3082\u5104\u52ab\u306a\u6c17\u304c\u3057\u305f\u306e\u3067\u306a\u3089\u3044\u3063\u305d\u4f5c\u3063\u3066\u8a66\u3057\u3061\u3083\u3048\u3002\u305d\u3046\u601d\u3063\u3066\u4f5c\u308a\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<div class=\"linkcard\"><div class=\"lkc-external-wrap\"><a class=\"lkc-link no_icon\" href=\"https:\/\/github.com\/step63r\/python-list-comprehension\" target=\"_blank\" rel=\"external noopener\"><div class=\"lkc-card\"><div class=\"lkc-info\"><div class=\"lkc-favicon\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.google.com\/s2\/favicons?domain=github.com\" alt=\"\" width=\"16\" height=\"16\" \/><\/div><div class=\"lkc-domain\">GitHub<\/div><\/div><div class=\"lkc-content\"><figure class=\"lkc-thumbnail\"><img decoding=\"async\" class=\"lkc-thumbnail-img\" src=\"\/\/blog.minatoproject.com\/wp-content\/uploads\/pz-linkcard\/cache\/d5c4cbd8f897a8944ceca2e6939e2d3a6b51649effd4f3f5c60a70dd6fe857ed.jpeg\" width=\"100px\" height=\"108px\" alt=\"\" \/><\/figure><div class=\"lkc-title\">step63r\/python-list-comprehension<\/div><div class=\"lkc-url\" title=\"https:\/\/github.com\/step63r\/python-list-comprehension\">https:\/\/github.com\/step63r\/python-list-comprehension<\/div><div class=\"lkc-excerpt\">Speed test of list iteration vs list comprehension - step63r\/python-list-comprehension<\/div><\/div><div class=\"clear\"><\/div><\/div><\/a><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9f\u9a131. 1000\u4e07\u500b\u306e\u6574\u6570<\/h2>\n\n\n\n<p>\u305d\u308c\u305e\u308c\u4e0a\u304cfor\u30eb\u30fc\u30d7\u3001\u4e0b\u304c\u30ea\u30b9\u30c8\u5185\u5305\u8868\u8a18\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-plane\"><code>--------------------------------------------------\nList int with iteration\ntime: 1296.9629764556885 ms\n--------------------------------------------------\n--------------------------------------------------\nList int with comprehension\ntime: 529.3018817901611 ms\n--------------------------------------------------<\/code><\/pre><\/div>\n\n\n\n<p>5\u500d\u3068\u307e\u3067\u306f\u3044\u304b\u306a\u304b\u3063\u305f\u3067\u3059\u304c\u30ea\u30b9\u30c8\u5185\u5305\u8868\u8a18\u306e\u65b9\u304c2\u500d\u4ee5\u4e0a\u901f\u3044\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9f\u9a132. 1000\u4e07\u500b\u306e\u30e9\u30f3\u30c0\u30e0\u306a\u5c0f\u6587\u5b57\u82f1\u5b57<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-plane\"><code>--------------------------------------------------\nList str with iteration\ntime: 14827.327489852905 ms\n--------------------------------------------------\n--------------------------------------------------\nList str with comprehension\ntime: 13321.378707885742 ms\n--------------------------------------------------<\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u3061\u3089\u306f\u3055\u307b\u3069\u5dee\u304c\u898b\u53d7\u3051\u3089\u308c\u307e\u305b\u3093\u3067\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u3068\u3044\u3046\u3088\u308a\u306f <code>random.choice()<\/code> \u306e\u30aa\u30fc\u30d0\u30fc\u30d8\u30c3\u30c9\u304c\u5927\u304d\u304b\u3063\u305f\u306e\u304b\u3082\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9f\u9a133. 100\u52171\u4e07\u884c\u306e\u30e9\u30f3\u30c0\u30e0\u306a\u6574\u6570\u306eDataFrame<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism off-numbers lang-plane\"><code>--------------------------------------------------\ndf with iteration\ntime: 40496.30618095398 ms\n--------------------------------------------------\n--------------------------------------------------\ndf with comprehension\ntime: 1698.488473892212 ms\n--------------------------------------------------<\/code><\/pre><\/div>\n\n\n\n<p>for\u306e\u65b9\u306f <code>Series<\/code> \u306b\u3057\u305f\u308a <code>append<\/code> \u3057\u305f\u308a\u3059\u308b\u305f\u3081\u306e\u6642\u9593\u304c\u3042\u308a\u307e\u3059\u304c\u5165\u308c\u5b50\u306e\u30eb\u30fc\u30d7\u306e\u5834\u5408\u306f20\u500d\u4ee5\u4e0a\u901f\u304f\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u307e\u3068\u3081<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>\u30a4\u30c6\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u5185\u90e8\u3067\u3084\u3063\u3066\u3044\u308b\u51e6\u7406\u306e\u30aa\u30fc\u30d0\u30fc\u30d8\u30c3\u30c9\u306b\u3088\u3063\u3066\u901f\u5ea6\u6539\u5584\u306e\u52b9\u679c\u306f\u5909\u308f\u308b<\/li><li>\u3068\u306f\u3044\u3048\u3042\u308b\u7a0b\u5ea6\u306e\u30b1\u30fc\u30b9\u3067\u300c\u4f7f\u3048\u308b\u306a\u3089\u30ea\u30b9\u30c8\u5185\u5305\u8868\u8a18\u300d\u304c\u6b63\u89e3\u3068\u8a00\u3048\u308b\u306e\u304b\u3082<\/li><li><code>yield<\/code> \u3092\u4f7f\u3044\u3053\u306a\u305b\u3066\u3044\u306a\u3044\u3070\u304b\u308a\u306b\u540c\u3058\u51e6\u7406\u3092\u4f55\u5ea6\u3082\u66f8\u304f\u6b8b\u5ff5\u30b3\u30fc\u30c9\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u3053\u3068\u3060\u306a\u3041\uff01<\/li><\/ul>\n\n\n\n<p>\u4ee5\u4e0a\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python\u3067\u306f\u4e00\u822c\u7684\u306b\u5358\u7d14\u306a\u30ea\u30b9\u30c8\u8ffd\u52a0\u306e\u30eb\u30fc\u30d7\u3092\u56de\u3059\u5834\u5408\u3001for\u3067\u56f2\u3046\u3088\u308a\u3082\u30ea\u30b9\u30c8\u5185\u5305\u8868\u8a18\u3068\u3044\u3046\u306e\u3092\u4f7f\u3063\u305f\u65b9\u304c\u6700\u5927\u30675\u500d\u7a0b\u5ea6\u9ad8\u901f\u3067\u3042\u308b\u3068\u3044\u3046\u4fd7\u8aac\u304c\u3042\u308a\u307e\u3059\u3002 \u4f8b\u3048\u3070\u5358\u7d14\u306afor\u30eb\u30fc\u30d7\u3067\u56de\u3059\u5834\u5408\u3001 \u3068\u304b\u3084\u308a\u307e\u3059\u304c\u3001\u3053\u308c\u3068 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1571,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"vkexunit_cta_each_option":"","footnotes":""},"categories":[6],"tags":[],"class_list":["post-1411","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.minatoproject.com\/index.php?rest_route=\/wp\/v2\/posts\/1411","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.minatoproject.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.minatoproject.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.minatoproject.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.minatoproject.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1411"}],"version-history":[{"count":6,"href":"https:\/\/blog.minatoproject.com\/index.php?rest_route=\/wp\/v2\/posts\/1411\/revisions"}],"predecessor-version":[{"id":1767,"href":"https:\/\/blog.minatoproject.com\/index.php?rest_route=\/wp\/v2\/posts\/1411\/revisions\/1767"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.minatoproject.com\/index.php?rest_route=\/wp\/v2\/media\/1571"}],"wp:attachment":[{"href":"https:\/\/blog.minatoproject.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.minatoproject.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.minatoproject.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}