{"id":3789,"date":"2010-08-04T22:26:58","date_gmt":"2010-08-04T13:26:58","guid":{"rendered":"http:\/\/www.gesource.jp\/weblog\/?p=3789"},"modified":"2017-07-16T15:08:54","modified_gmt":"2017-07-16T06:08:54","slug":"python%e3%81%a7%e7%9b%b4%e7%a9%8d%e3%82%92%e6%b1%82%e3%82%81%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.gesource.jp\/weblog\/?p=3789","title":{"rendered":"Python\u3067\u76f4\u7a4d\u3092\u6c42\u3081\u308b"},"content":{"rendered":"<p>Python\u3067\u76f4\u7a4d\u3092\u6c42\u3081\u308b\u306b\u306f\u3001Python2.6\u3067\u5c0e\u5165\u3055\u308c\u305f<a href=\"http:\/\/pythonjp.sourceforge.jp\/dev\/library\/itertools.html#itertools.product\">itertools.product<\/a>\u3092\u4f7f\u3046\u3002<\/p>\n<pre><code>from itertools import product\n<\/code><\/pre>\n<p>Python2.5\u4ee5\u524d\u3067\u306f\u3001\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u793a\u3055\u308c\u3066\u3044\u308b<a href=\"http:\/\/pythonjp.sourceforge.jp\/dev\/library\/itertools.html#itertools.product\">itertools.product<\/a>\u3068\u7b49\u4fa1\u306e\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u4f7f\u3046\u3002<\/p>\n<pre><code>def product(*args, **kwds):\n    pools = map(tuple, args) * kwds.get('repeat', 1)\n    result = [[]]\n    for pool in pools:\n        result = [x+[y] for x in result for y in pool]\n    for prod in result:\n        yield tuple(prod)\n<\/code><\/pre>\n<p>\u7c21\u5358\u306a\u4f8b<\/p>\n<pre><code>&gt;&gt;&gt; for i in product(('a','b','c'), ('X','Y'), ('1','2')):\n...   print i\n...\n('a', 'X', '1')\n('a', 'X', '2')\n('a', 'Y', '1')\n('a', 'Y', '2')\n('b', 'X', '1')\n('b', 'X', '2')\n('b', 'Y', '1')\n('b', 'Y', '2')\n('c', 'X', '1')\n('c', 'X', '2')\n('c', 'Y', '1')\n('c', 'Y', '2')\n<\/code><\/pre>\n<p>\u5f15\u6570\u306e\u30a4\u30c6\u30e9\u30d6\u30eb\u304c\u540c\u3058\u6642\u306frepeat\u3067\u7e70\u308a\u8fd4\u3057\u56de\u6570\u3092\u6307\u5b9a\u3067\u304d\u308b\u3002<\/p>\n<p>\u300cproduct((&#8216;1&#8242;,&#8217;2&#8217;), repeat=3)\u300d\u306f\u300cproduct((&#8216;1&#8242;,&#8217;2&#8217;), (&#8216;1&#8242;,&#8217;2&#8217;), (&#8216;1&#8242;,&#8217;2&#8217;))\u300d\u3068\u540c\u3058\u3002<\/p>\n<pre><code>&gt;&gt;&gt; for i in product(('1','2'), repeat=3):\n...   print i\n...\n('1', '1', '1')\n('1', '1', '2')\n('1', '2', '1')\n('1', '2', '2')\n('2', '1', '1')\n('2', '1', '2')\n('2', '2', '1')\n('2', '2', '2')\n<\/code><\/pre>\n<div class=\"booklink-box\" style=\"text-align:left;padding-bottom:20px;font-size:small;\/zoom: 1;overflow: hidden;\">\n<div class=\"booklink-image\" style=\"float:left;width:110px;margin:0 15px 10px 0;\"><a href=\"http:\/\/www.amazon.co.jp\/exec\/obidos\/ASIN\/4774138053\/gesource-22\/ref=nosim\/\" name=\"booklink\" rel=\"nofollow\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/ecx.images-amazon.com\/images\/I\/51WeqtvvDuL._SL160_.jpg?w=730\" style=\"border: none;\" \/><\/a><\/div>\n<div class=\"booklink-info\" style=\"line-height:120%;\/zoom: 1;overflow: hidden;\">\n<div class=\"booklink-name\" style=\"margin-bottom:10px;line-height:120%\"><a href=\"http:\/\/www.amazon.co.jp\/exec\/obidos\/ASIN\/4774138053\/gesource-22\/ref=nosim\/\" name=\"booklink\" rel=\"nofollow\" target=\"_blank\">Python \u30dd\u30b1\u30c3\u30c8\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9 (Pocket Reference)<\/a><\/p>\n<div class=\"booklink-powered-date\" style=\"font-size:8pt;margin-top:5px;font-family:verdana;line-height:120%\">posted with <a href=\"http:\/\/yomereba.com\" target=\"_blank\">\u30e8\u30e1\u30ec\u30d0<\/a> at 10.07.31<\/div>\n<\/div>\n<div class=\"booklink-detail\" style=\"margin-bottom:5px;\">\u67cf\u91ce \u96c4\u592a \u6280\u8853\u8a55\u8ad6\u793e 2009-03-28    <\/div>\n<div class=\"booklink-link2\" style=\"margin-top:10px\">\n<div class=\"shoplinkamazon\" style=\"margin-right:5px;background: url('http:\/\/farm5.static.flickr.com\/4037\/4697852771_31c83a63a3.jpg') 0 0 no-repeat;padding: 2px 0 2px 18px;white-space: nowrap;\"><a href=\"http:\/\/www.amazon.co.jp\/exec\/obidos\/asin\/4774138053\/gesource-22\/\" rel=\"nofollow\" target=\"_blank\" title=\"\u30a2\u30de\u30be\u30f3\" >Amazon<\/a><\/div>\n<div class=\"shoplinkrakuten\" style=\"margin-right:5px;background: url('http:\/\/farm5.static.flickr.com\/4037\/4697852771_31c83a63a3.jpg') 0 -50px no-repeat;padding: 2px 0 2px 18px;white-space: nowrap;\"><a href=\"http:\/\/pt.afl.rakuten.co.jp\/c\/09af7168.5e4175d8\/?url=http%3A%2F%2Fbooks.rakuten.co.jp%2Frb%2F6022413%2F\" rel=\"nofollow\" target=\"_blank\" title=\"\u697d\u5929\u5e02\u5834\" >\u697d\u5929\u30d6\u30c3\u30af\u30b9<\/a><\/div>\n<div class=\"shoplinkseven\" style=\"margin-right:5px;background: url('http:\/\/farm5.static.flickr.com\/4037\/4697852771_31c83a63a3.jpg') 0 -100px no-repeat;padding: 2px 0 2px 18px;white-space: nowrap;\"><a href=\"http:\/\/click.linksynergy.com\/fs-bin\/click?id=aEiZExlwPrs&#038;subid=&#038;offerid=197738.1&#038;type=10&#038;tmpid=1787&#038;RD_PARM1=http%253A%252F%252Fwww.7netshopping.jp%252Fbooks%252Fsearch_result%252F%253Fctgy%253Dbooks%2526code%253D4774138053\" rel=\"nofollow\" target=\"_blank\" title=\"\u30bb\u30d6\u30f3\u30cd\u30c3\u30c8\u30b7\u30e7\u30c3\u30d4\u30f3\u30b0\" >7net<\/a><\/div>\n<div class=\"shoplinkbk1\" style=\"margin-right:5px;background: url('http:\/\/farm5.static.flickr.com\/4037\/4697852771_31c83a63a3.jpg') 0 -150px no-repeat;padding: 2px 0 2px 18px;white-space: nowrap;\"><a href=\"http:\/\/ck.jp.ap.valuecommerce.com\/servlet\/referral?sid=2300256&#038;pid=879367607&#038;vc_url=http%3A%2F%2Fwww.bk1.jp%2FkeywordSearchResult%2F%3Fkeyword%3D4774138053\" target=\"_blank\" title=\"bk1\" >bk1<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/ad.jp.ap.valuecommerce.com\/servlet\/gifbanner?sid=2300256&#038;pid=879367607\" height=\"1\" width=\"1\" border=\"0\"><\/a><\/div>\n<div class=\"shoplinkbookoff\" style=\"margin-right:5px;background: url('http:\/\/farm5.static.flickr.com\/4037\/4697852771_31c83a63a3.jpg') 0 -200px no-repeat;padding: 2px 0 2px 18px;white-space: nowrap;\"><a href=\"http:\/\/click.linksynergy.com\/fs-bin\/click?id=aEiZExlwPrs&#038;subid=&#038;offerid=169505.1&#038;type=10&#038;tmpid=3677&#038;RD_PARM1=http%253A%252F%252Fwww.bookoffonline.co.jp%252Fdisplay%252FL001%252Cbg%253D12%252Cq%253D9784774138053\" rel=\"nofollow\" target=\"_blank\" title=\"\u30d6\u30c3\u30af\u30aa\u30d5\u30aa\u30f3\u30e9\u30a4\u30f3\" >\u30d6\u30c3\u30af\u30aa\u30d5<\/a><\/div>\n<div class=\"shoplinkehon\" style=\"margin-right:5px;background: url('http:\/\/farm5.static.flickr.com\/4037\/4697852771_31c83a63a3.jpg') 0 -250px no-repeat;padding: 2px 0 2px 18px;white-space: nowrap;\"><a href=\"http:\/\/ck.jp.ap.valuecommerce.com\/servlet\/referral?sid=2300256&#038;pid=879356331&#038;vc_url=http%3A%2F%2Fwww.e-hon.ne.jp%2Fbec%2FSA%2FDetail%3FrefISBN%3D4774138053\" target=\"_blank\" title=\"e-hon\" >e-hon<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/ad.jp.ap.valuecommerce.com\/servlet\/gifbanner?sid=2300256&#038;pid=879356331\" height=\"1\" width=\"1\" border=\"0\"><\/a><\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Python\u3067\u76f4\u7a4d\u3092\u6c42\u3081\u308b\u306b\u306f\u3001Python2.6\u3067\u5c0e\u5165\u3055\u308c\u305fitertools.product\u3092\u4f7f\u3046\u3002 from itertools import product Python2.5\u4ee5\u524d\u3067\u306f\u3001\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u793a\u3055\u308c\u3066\u3044\u308b &#8230;<\/p>\n<p><a href=\"https:\/\/www.gesource.jp\/weblog\/?p=3789\" class=\"more-link\">Continue reading &lsquo;Python\u3067\u76f4\u7a4d\u3092\u6c42\u3081\u308b&rsquo; &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[7],"tags":[143],"class_list":["post-3789","post","type-post","status-publish","format-standard","hentry","category-python","tag-python"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/posts\/3789","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3789"}],"version-history":[{"count":0,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/posts\/3789\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}