{"id":283,"date":"2017-02-08T12:46:40","date_gmt":"2017-02-08T03:46:40","guid":{"rendered":"http:\/\/www.python.ambitious-engineer.com\/?p=283"},"modified":"2020-01-07T18:18:01","modified_gmt":"2020-01-07T09:18:01","slug":"lambda%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/www.python.ambitious-engineer.com\/archives\/283","title":{"rendered":"Lambda\u5f0f"},"content":{"rendered":"<h2>lambda\u5f0f\u3068\u306f<\/h2>\n<p>lambda(\u30e9\u30e0\u30c0)\u5f0f\u3068\u306f\u3001\u4e00\u6642\u7684\u306b\u5229\u7528\u3059\u308b\u7121\u540d\u95a2\u6570\u3092\u8a18\u8ff0\u3059\u308b\u65b9\u6cd5\u3067\u3001\u4ee5\u4e0b\u306e\u5f62\u5f0f\u3067\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<div class=\"c_box intitle yellow_box\"><div class=\"box_title\"><span>lambda\u5f0f<\/span><\/div>\nlambda \u5f15\u6570: \u623b\u308a\u5024<br \/>\n<\/div>\n<p>\u30b5\u30f3\u30d7\u30eb\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u4ee5\u4e0b\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u306f\u5f15\u6570x\u304c\u5947\u6570\u304b\u3069\u3046\u304b\u3092\u5224\u5b9a\u3057\u305f\u7d50\u679c\u3092\u8fd4\u3059\u95a2\u6570\u3092lambda\u5f0f\u3067\u8a18\u8ff0\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nfunc = lambda x: x % 2 == 1\r\n\r\nis_odd = func(5)\r\nprint(is_odd)  # True\r\n\r\nis_odd = func(6)\r\nprint(is_odd)  # False\r\n<\/pre>\n<p>func\u306b\u306f\u3001\u5f15\u6570x\u306b\u5bfe\u3057\u3001\u5f15\u6570x\u304c\u5947\u6570\u304b\u3069\u3046\u304b\u3092\u5224\u5b9a\u3057\u305f\u7d50\u679c\u3092\u8fd4\u3059\u95a2\u6570\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u683c\u7d0d\u3055\u308c\u307e\u3059\u3002\u308f\u304b\u308a\u3065\u3089\u3044\u65b9\u306f\u4ee5\u4e0b\u306bdef\u3092\u4f7f\u3063\u305f\u5834\u5408\u3068\u6bd4\u8f03\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ndef is_odd(x): \r\n    return x % 2 == 1\r\n\r\nfunc = is_odd \r\n\r\nis_odd = func(5)\r\nprint(is_odd)  # True\r\n\r\nis_odd = func(6)\r\nprint(is_odd)  # False\r\n<\/pre>\n<p>\u7c21\u5358\u306a\u95a2\u6570\u3060\u3068\u3001lambda\u5f0f\u3067\u77ed\u304f\u66f8\u3051\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059\u306d\u3002<\/p>\n<h2>lambda\u5f0f\u306e\u30e1\u30ea\u30c3\u30c8<\/h2>\n<h3>\u9ad8\u968e\u95a2\u6570<\/h3>\n<p>\u3067\u306f\u3001\u77ed\u304f\u66f8\u3051\u308b\u4ee5\u5916\u306blambda\u5f0f\u3092\u4f7f\u3046\u3068\u4f55\u304c\u3044\u3044\u306e\u3067\u3057\u3087\u3046\u304b\uff1f\u305d\u306e\u30e1\u30ea\u30c3\u30c8\u3092\u8aac\u660e\u3059\u308b\u524d\u306b\u3001\u9ad8\u968e\u95a2\u6570\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><a href=\"http:\/\/www.python.ambitious-engineer.com\/archives\/264\">\u95a2\u6570\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/a>\u306e\u30da\u30fc\u30b8\u3067\u8aac\u660e\u3057\u305f\u3068\u304a\u308a\u3001Python\u306e\u95a2\u6570\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u3057\u3066\u6271\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u7279\u306b\u3001\u95a2\u6570\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u5f15\u6570\u3084\u623b\u308a\u5024\u306b\u3059\u308b\u3082\u306e\u3092\u9ad8\u968e\u95a2\u6570\u3068\u547c\u3073\u307e\u3059\u3002<\/p>\n<p><strong>\u9ad8\u968e\u95a2\u6570\u306e\u4f8b<\/strong><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ndef higher_order(datas, is_target):\r\n    &quot;&quot;&quot; \u9ad8\u968e\u95a2\u6570\u306e\u30b5\u30f3\u30d7\u30eb &quot;&quot;&quot;\r\n    for i in datas:\r\n        if is_target(i):\r\n            print(i)\r\n\r\ndef is_odd(num):\r\n    return num % 2 == 1\r\n\r\ndatas = [1, 102, 900, 5, 3]\r\nhigher_order(datas, is_odd)\r\n<\/pre>\n<p>higher_order\u306f\u9ad8\u968e\u95a2\u6570\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u3001\u5f15\u6570\u3067\u6307\u5b9a\u3055\u308c\u305f\u30c7\u30fc\u30bf\u30ea\u30b9\u30c8\u306b\u5bfe\u3057\u3001\u5f15\u6570\u3067\u6307\u5b9a\u3055\u308c\u305f\u5224\u5b9a\u30ed\u30b8\u30c3\u30af\u306b\u8a72\u5f53\u3059\u308b\u30c7\u30fc\u30bf\u304c\u3042\u308c\u3070\u305d\u308c\u3092print\u3067\u51fa\u529b\u3059\u308b\u95a2\u6570\u3067\u3059\u3002<\/p>\n<p>\u4e0a\u8a18\u30b5\u30f3\u30d7\u30eb\u3067\u306f\u3001\u5224\u5b9a\u30ed\u30b8\u30c3\u30af\u306b\u300c\u5947\u6570\u304b\u3069\u3046\u304b\u3092\u5224\u5b9a\u3059\u308b\u95a2\u6570\u300d\u3092\u6e21\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001\u300c3\u306e\u500d\u6570\u304b\u3069\u3046\u304b\u3092\u5224\u5b9a\u300d\u3059\u308b\u5834\u5408\u306f\u3069\u3046\u3059\u308c\u3070\u3088\u3044\u3067\u3057\u3087\u3046\u304b\uff1f<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ndef higher_order(datas, is_target):\r\n    &quot;&quot;&quot; \u9ad8\u968e\u95a2\u6570\u306e\u30b5\u30f3\u30d7\u30eb &quot;&quot;&quot;\r\n    for i in datas:\r\n        if is_target(i):\r\n            print(i)\r\n\r\ndef is_multipleof3(num):\r\n    return num % 3 == 0\r\n\r\ndatas = [1, 102, 900, 5, 3]\r\nhigher_order(datas, is_multipleof3) \r\n<\/pre>\n<p>\u300c3\u306e\u500d\u6570\u304b\u3069\u3046\u304b\u3092\u5224\u5b9a\u3059\u308b\u95a2\u6570\u300d\u3092\u5f15\u6570\u306b\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<b>\u9ad8\u968e\u95a2\u6570\u81ea\u8eab\u306b\u4fee\u6b63\u304c\u5165\u3089\u306a\u3044<\/b>\u70b9\u306b\u30e1\u30ea\u30c3\u30c8\u304c\u3042\u308a\u307e\u3059\u306d\u3002<\/p>\n<h3>lambda\u5f0f\u306e\u30e1\u30ea\u30c3\u30c8<\/h3>\n<p>\u305d\u308c\u3067\u306f\u3044\u3088\u3044\u3088lambda\u5f0f\u306e\u4f7f\u3044\u3069\u3053\u308d\u306b\u3064\u3044\u3066\u3067\u3059\u3002\u3082\u3046\u304a\u6c17\u3065\u304d\u306e\u65b9\u3082\u591a\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u9ad8\u968e\u95a2\u6570\u3092\u5229\u7528\u3059\u308b\u969b\u306e\u4f7f\u3044\u304d\u308a\u306e\u95a2\u6570\u3067\u308f\u3056\u308f\u3056def\u3067\u66f8\u304f\u306e\u306f\u9762\u5012\u3067\u3059\u3002\u305d\u3053\u3067\u3001\u4e0a\u306e\u9ad8\u968e\u95a2\u6570\u3092lambda\u5f0f\u3067\u66f8\u304d\u306a\u304a\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ndef higher_order(datas, is_target):\r\n    &quot;&quot;&quot; \u9ad8\u968e\u95a2\u6570\u306e\u30b5\u30f3\u30d7\u30eb &quot;&quot;&quot;\r\n    for i in datas:\r\n        if is_target(i):\r\n            print(i)\r\n\r\ndatas = [1, 102, 900, 5, 3]\r\nhigher_order(datas, lambda x : x % 2 == 1)\r\n<\/pre>\n<p>\u3044\u304b\u304c\u3067\u3057\u3087\u3046\u304b\u3002\u95a2\u6570\u3092\u77ed\u304f\u66f8\u3051\u305f\u4e0a\u3001\u4f7f\u3044\u6368\u3066\u306e\u5c0f\u3055\u3044\u95a2\u6570\u304c\u306a\u304f\u306a\u3063\u305f\u305f\u3081\u3001\u5168\u4f53\u7684\u306b\u30b9\u30c3\u30ad\u30ea\u3057\u3066\u672c\u7b4b\u304c\u8aad\u307f\u3084\u3059\u304f\u306a\u3063\u305f\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\uff1f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>lambda\u5f0f\u3068\u306f lambda(\u30e9\u30e0\u30c0)\u5f0f\u3068\u306f\u3001\u4e00\u6642\u7684\u306b\u5229\u7528\u3059\u308b\u7121\u540d\u95a2\u6570\u3092\u8a18\u8ff0\u3059\u308b\u65b9\u6cd5\u3067\u3001\u4ee5\u4e0b\u306e\u5f62\u5f0f\u3067\u8a18\u8ff0\u3057\u307e\u3059\u3002 \u30b5\u30f3\u30d7\u30eb\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u4ee5\u4e0b\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u306f\u5f15\u6570x\u304c\u5947\u6570\u304b\u3069\u3046\u304b\u3092\u5224\u5b9a\u3057\u305f\u7d50\u679c\u3092\u8fd4\u3059\u95a2\u6570\u3092lambda...<\/p>\n","protected":false},"author":1,"featured_media":3487,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[210],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/283"}],"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=283"}],"version-history":[{"count":5,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/283\/revisions"}],"predecessor-version":[{"id":2596,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/283\/revisions\/2596"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media\/3487"}],"wp:attachment":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media?parent=283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/categories?post=283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/tags?post=283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}