{"id":1013,"date":"2017-04-29T11:31:34","date_gmt":"2017-04-29T02:31:34","guid":{"rendered":"http:\/\/www.python.ambitious-engineer.com\/?p=1013"},"modified":"2018-01-15T23:41:26","modified_gmt":"2018-01-15T14:41:26","slug":"reduce%e9%96%a2%e6%95%b0-%e3%82%b7%e3%83%bc%e3%82%b1%e3%83%b3%e3%82%b9%e3%81%ae%e5%80%a4%e3%82%92%e7%b4%af%e7%a9%8d%e7%9a%84%e3%81%ab%e9%9b%86%e7%b4%84%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.python.ambitious-engineer.com\/archives\/1013","title":{"rendered":"reduce\u95a2\u6570 \u30b7\u30fc\u30b1\u30f3\u30b9\u306e\u5024\u3092\u7d2f\u7a4d\u7684\u306b\u96c6\u7d04\u3059\u308b"},"content":{"rendered":"<p>Python2\u307e\u3067\u306f\u7d44\u8fbc\u307f\u3067rudece\u95a2\u6570\u3068\u3044\u3046\u3082\u306e\u304c\u3042\u3063\u305f\u306e\u3067\u3059\u304c\u3001Python3\u3067\u306ffunctools\u3068\u3044\u3046\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u95a2\u6570\u3068\u3057\u3066\u63d0\u4f9b\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u7d44\u307f\u8fbc\u307f\u95a2\u6570\u3067\u306f\u306a\u3044\u306e\u3067\u3059\u304c\u3001map\u3001filter\u3001zip\u95a2\u6570\u3068\u3068\u3082\u306b\u3088\u304f\u4f7f\u7528\u3059\u308b\u305f\u3081\u3001\u5408\u308f\u305b\u3066\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<h2>reduce\u95a2\u6570<\/h2>\n<p>reduce\u95a2\u6570\u306f\u30ea\u30b9\u30c8\u7b49\u306e\u30b7\u30fc\u30b1\u30f3\u30b9\u306e\u5024\u3092\u7d2f\u7a4d\u7684\u306b\u8a08\u7b97\u3092\u884c\u30441\u3064\u306e\u5024\u306b\u96c6\u7d04\u3057\u307e\u3059\u30021\u756a\u76ee\u306e\u5f15\u6570\u306b\u3001\u5f15\u6570\u30922\u3064\u6301\u3064\u95a2\u6570\u3092\u30012\u756a\u76ee\u306b\u30ea\u30b9\u30c8\u7b49\u306e\u30b7\u30fc\u30b1\u30f3\u30b9\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u65e5\u672c\u8a9e\u306e\u8aac\u660e\u3088\u308a\u3082\u3001\u6700\u521d\u306b\u30b5\u30f3\u30d7\u30eb\u3092\u8aad\u3093\u3060\u307b\u3046\u304c\u308f\u304b\u308a\u3084\u3059\u3044\u3067\u3057\u3087\u3046\u3002\u4ee5\u4e0b\u306f\u30011\u301c4\u307e\u3067\u306e\u548c\u3092\u6c42\u3081\u308b\u30b5\u30f3\u30d7\u30eb\u3067\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nfrom functools import reduce\r\n\r\ndef add(arg1, arg2):\r\n    &quot;&quot;&quot; 2\u3064\u306e\u5024\u3092\u8db3\u3057\u3066\u8fd4\u3059 &quot;&quot;&quot;\r\n    return arg1 + arg2\r\n\r\nx = reduce(add, [1, 2, 3, 4])\r\nprint(x) # 10\r\n<\/pre>\n<p>\u3053\u308c\u306f\u3064\u307e\u308a\u3001add(add(add(1, 2), 3), 4) = (((1 + 2) + 3) + 4) = 1 + 2 + 3 + 4 \u3068\u540c\u3058\u3053\u3068\u3067\u3059\u306d\u3002\u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u5206\u6790\u7b49\u3001\u7d2f\u7a4d\u3057\u305f\u524d\u56de\u306e\u5024\u3092\u4f7f\u7528\u3059\u308b\u8a08\u7b97\u3067\u3088\u304f\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<h2>\u88dc\u8db3 lambda\u5f0f\u3068\u7d44\u307f\u5408\u308f\u305b\u308b<\/h2>\n<p>\u3044\u3064\u3082\u306e\u6d41\u308c\u3067\u3059\u3002\u3084\u306f\u308a\u4e0a\u306e\u3088\u3046\u306a\u7c21\u5358\u306a\u9ad8\u968e\u95a2\u6570\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306flambda\u3092\u4f7f\u7528\u3057\u305f\u307b\u3046\u304c\u826f\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nfrom functools import reduce\r\n\r\nx = reduce(lambda x, y: x + y, [1, 2, 3, 4])\r\nprint(x) # 10\r\n<\/pre>\n<p>\u3044\u3064\u3082\u901a\u308a\u3001\u305a\u3044\u3076\u3093\u30b9\u30c3\u30ad\u30ea\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<h2>\u88dc\u8db32 \u5fc5\u305a\u3057\u3082\u4e21\u65b9\u306e\u5f15\u6570\u3092\u4f7f\u3046\u5fc5\u8981\u306f\u306a\u3044<\/h2>\n<p>reduce\u306e\u4e00\u756a\u76ee\u306e\u5f15\u6570\u306f\u3001\u5f15\u6570\u30922\u3064\u3082\u3064\u95a2\u6570\u3092\u6307\u5b9a\u3057\u307e\u3059\u304c\u3001\u524d\u56de\u306e\u5024\u304b\u3089\u5c0e\u51fa\u3067\u304d\u308b\u5834\u5408\u306f2\u756a\u76ee\u306e\u5f15\u6570\u3092\u4f7f\u308f\u306a\u3044\u5834\u5408\u3082\u3042\u308a\u307e\u3059\u3002\u4f8b\u3048\u30707%\u306e\u91d1\u5229\u306711\u5e74\u9593\u8907\u5229\u3067\u56de\u3057\u305f\u5834\u5408\u306e\u8a08\u7b97\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u30020\u5e74\u59cb\u307e\u308a\u306a\u306e\u3067\u3001\u8981\u7d20\u6570\u306f12\u3092\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nfrom functools import reduce\r\n\r\ndef kinri(arg1, arg2):\r\n    return arg1 + arg1 * 0.07\r\n\r\nx = reduce(kinri, [100] * 12)\r\nprint(x)\r\n<\/pre>\n<p>7%\u8907\u5229\u309211\u5e74\u9593\u56de\u3059\u30682\u500d\u306b\u306a\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002\uff08\u4f59\u8ac7\u3067\u3059\u304c\u91d1\u878d\u696d\u754c\u3067\u306f\u3053\u308c\u3092\u30bb\u30d6\u30f3\u30a4\u30ec\u30d6\u30f3\u306e\u6cd5\u5247\u3068\u547c\u3093\u3067\u3044\u307e\u3057\u305f\u3002\uff09<br \/>\n<br \/>&nbsp;<br \/>\n\u5c11\u3005\u7121\u7406\u3084\u308a\u306a\u8aac\u660e\u3067\u3057\u305f\u304c\u3001\u4e00\u90e8\u306e\u5f15\u6570\u3092\u4f7f\u308f\u306a\u304f\u3066\u6e08\u3080\u5834\u5408\u3082\u3042\u308b\u3001\u3068\u3044\u3046\u308f\u3051\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python2\u307e\u3067\u306f\u7d44\u8fbc\u307f\u3067rudece\u95a2\u6570\u3068\u3044\u3046\u3082\u306e\u304c\u3042\u3063\u305f\u306e\u3067\u3059\u304c\u3001Python3\u3067\u306ffunctools\u3068\u3044\u3046\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u95a2\u6570\u3068\u3057\u3066\u63d0\u4f9b\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u7d44\u307f\u8fbc\u307f\u95a2\u6570\u3067\u306f\u306a\u3044\u306e\u3067\u3059\u304c\u3001map\u3001filter\u3001zip\u95a2\u6570...<\/p>\n","protected":false},"author":1,"featured_media":3616,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[136],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/1013"}],"collection":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/comments?post=1013"}],"version-history":[{"count":5,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/1013\/revisions"}],"predecessor-version":[{"id":3615,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/1013\/revisions\/3615"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media\/3616"}],"wp:attachment":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media?parent=1013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/categories?post=1013"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/tags?post=1013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}