{"id":670,"date":"2017-03-12T21:57:08","date_gmt":"2017-03-12T12:57:08","guid":{"rendered":"http:\/\/www.python.ambitious-engineer.com\/?p=670"},"modified":"2020-01-07T18:54:49","modified_gmt":"2020-01-07T09:54:49","slug":"map%e9%96%a2%e6%95%b0-list%e3%81%ae%e5%85%a8%e3%81%a6%e8%a6%81%e7%b4%a0%e3%81%ab%e5%af%be%e3%81%97%e3%81%a6%e5%90%8c%e3%81%98%e5%87%a6%e7%90%86%e3%82%92%e8%a1%8c%e3%81%86","status":"publish","type":"post","link":"https:\/\/www.python.ambitious-engineer.com\/archives\/670","title":{"rendered":"map\u95a2\u6570 \u30ea\u30b9\u30c8\u306e\u5168\u3066\u8981\u7d20\u306b\u5bfe\u3057\u3066\u540c\u3058\u51e6\u7406\u3092\u884c\u3046"},"content":{"rendered":"<h2>map\u95a2\u6570\u3068\u306f<\/h2>\n<p>map\u95a2\u6570\u306f\u30ea\u30b9\u30c8\u306a\u3069\u306e\u30a4\u30c6\u30e9\u30d6\u30eb\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306a\u5909\u6570\u306b\u5bfe\u3057\u3001\u305d\u306e\u5168\u3066\u306e\u8981\u7d20\u306b\u6307\u5b9a\u3057\u305f\u95a2\u6570\u3092\u5b9f\u884c\u3057\u3001\u7d50\u679c\u3092map\u578b\u3068\u547c\u3070\u308c\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u8fd4\u5374\u3057\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u5f15\u6570\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u304a\u305d\u3089\u304f\u3053\u308c\u3060\u3051\u3060\u3068\u4f55\u306e\u3053\u3068\u304b\u308f\u304b\u3089\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u306e\u3067\u3001\u5177\u4f53\u7684\u306a\u4f8b\u3092\u4ea4\u3048\u3066\u5b66\u7fd2\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<div class=\"c_box intitle yellow_box\"><div class=\"box_title\"><span>map\u95a2\u6570<\/span><\/div>\nmap(\u95a2\u6570\u30aa\u30d6\u30b8\u30a7\u30af\u30c8, \u30ea\u30b9\u30c8\u306a\u3069\u306e\u30a4\u30c6\u30e9\u30d6\u30eb\u306a\u5909\u6570)<br \/>\n<\/div>\n<h2>\u30ea\u30b9\u30c8\u306e\u5168\u3066\u306e\u8981\u7d20\u3092\u500d\u306b\u3059\u308b<\/h2>\n<p>\u5177\u4f53\u4f8b\u3068\u3057\u3066\u3001\u30ea\u30b9\u30c8\u306e\u5168\u3066\u306e\u8981\u7d20\u3092\u500d\u306b\u3059\u308b\u5834\u5408\u306b\u3064\u3044\u3066\u8003\u3048\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u3042\u308b\u6570\u5024\u3092\u500d\u306b\u3057\u3066\u8fd4\u3059\u95a2\u6570\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5b9a\u7fa9\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n# \u6570\u5024\u3092\u500d\u306b\u3059\u308b\u95a2\u6570\r\ndef calc_double(n):\r\n    return n * 2 \r\n\r\nx = 3 \r\ny = calc_double(x) # 3 * 2\u30676\u304c\u683c\u7d0d\u3055\u308c\u308b\r\n<\/pre>\n<p>\u3055\u3066\u3001\u3042\u308b\u30ea\u30b9\u30c8\u306e\u5168\u3066\u306e\u8981\u7d20\u5bfe\u3057\u3066calc_double\u3092\u5b9f\u884c\u3057\u3001\u7d50\u679c\u3092\u65b0\u305f\u306a\u30ea\u30b9\u30c8\u3068\u3057\u3066\u53d6\u5f97\u3059\u308b\u5834\u5408\u3001map\u95a2\u6570\u3092\u4f7f\u7528\u3059\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u540c\u3058\u51e6\u7406\u3092for\u6587\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\n# \u6570\u5024\u3092\u500d\u306b\u3059\u308b\u95a2\u6570\r\ndef calc_double(n):\r\n    return n * 2 \r\n\r\ndata1 = [1, 3, 6, 50, 5]\r\n\r\n# map\u95a2\u6570\u3092\u4f7f\u7528\u3057\u3066data1\u306e\u8981\u7d20\u3092\u5168\u3066\u500d\u306b\u3057\u3066data2\u306b\u683c\u7d0d\u3059\u308b\u5834\u5408\r\ndata2 = map(calc_double, data1)\r\nprint(list(data2))   # map\u3092list\u306b\u5909\u63db\u3057\u3066\u8868\u793a [2, 6, 12, 100, 10]\r\n<\/pre>\n<p>\u3044\u304b\u304c\u3067\u3057\u3087\u3046\u304b\uff1f\u65b0\u305f\u306b\u30ea\u30b9\u30c8\u3092\u4f5c\u6210\u3057\u3001\u30eb\u30fc\u30d7\u3067\u56de\u3057\u3066append\u3057\u3066\u30fb\u30fb\u30fb\u3068\u3044\u3046\u624b\u9593\u304c\u7701\u3051\u307e\u3059\u3002for\u3092\u4f7f\u7528\u3059\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n# \u6570\u5024\u3092\u500d\u306b\u3059\u308b\u95a2\u6570\r\ndef calc_double(n):\r\n    return n * 2 \r\n\r\ndata1 = [1, 3, 6, 50, 5]\r\n\r\n# for\u6587\u3092\u4f7f\u3063\u3066\u540c\u3058\u3053\u3068\u3092\u3059\u308b\u5834\u5408\r\ndata2 = []\r\nfor val in data1:\r\n    data2.append(calc_double(val))\r\n\r\n<\/pre>\n<p>\u305f\u3060\u30571\u70b9\u6ce8\u610f\u304c\u3042\u308a\u307e\u3059\u3002map\u95a2\u6570\u306e\u623b\u308a\u5024\u306f\u30ea\u30b9\u30c8\u3067\u306f\u306a\u304f\u30a4\u30c6\u30e9\u30d6\u30eb\u306amap\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u547c\u3070\u308c\u308b\u3082\u306e\u3067\u3059\u3002\u30eb\u30fc\u30d7\u51e6\u7406\u306f\u53ef\u80fd\u306a\u306e\u3067\u3059\u304c\u3001append\u7b49\u306e\u30ea\u30b9\u30c8\u306e\u30e1\u30bd\u30c3\u30c9\u306f\u4f7f\u7528\u3067\u304d\u307e\u305b\u3093\u3002\u307e\u305f\u3001print\u95a2\u6570\u3067\u51fa\u529b\u3057\u3066\u3082\u3001\u30ab\u30f3\u30de\u533a\u5207\u308a\u306e\u8981\u7d20\u3067\u306f\u8868\u793a\u3055\u308c\u305a\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u578b\u540d\u304c\u8868\u793a\u3055\u308c\u308b\u3060\u3051\u3067\u3059\u3002\u3067\u3059\u306e\u3067\u3001\u30ea\u30b9\u30c8\u306b\u3057\u305f\u3044\u5834\u5408\u306flist\u95a2\u6570\u3067\u5909\u63db\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p><font color=\"red\" size=\"2em\">2021\/10 \u300cmap\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u30b7\u30fc\u30b1\u30f3\u30b9\u300d\u3068\u3044\u3046\u8a18\u8ff0\u304c\u3042\u308a\u307e\u3057\u305f\u304c\u8aa4\u308a\u3067\u3042\u308b\u305f\u3081\u8a02\u6b63\u3057\u307e\u3057\u305f\u3002<\/font><\/p>\n<h2>\u88dc\u8db3 lambda\u5f0f\u3068\u7d44\u307f\u5408\u308f\u305b\u308b<\/h2>\n<p>\u3053\u306e\u624b\u3067\u4f7f\u7528\u3059\u308b\u77ed\u3044\u95a2\u6570\u3092\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u3057\u3066\u6271\u3046\u5834\u5408\u3001\u4e00\u822c\u7684\u306b<a href=\"http:\/\/www.python.ambitious-engineer.com\/archives\/283\">lambda\u5f0f<\/a>\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u591a\u3044\u3067\u3059\u3002lambda\u5f0f\u3092\u4f7f\u7528\u3057\u305f\u3082\u306e\u306b\u66f8\u304d\u76f4\u3059\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ndata1 = [1, 3, 6, 50, 5]\r\ndata2 = map(lambda x: x * 2, data1)\r\n<\/pre>\n<h2>\u88dc\u8db32 \u5b9f\u7528\u4f8b<\/h2>\n<p><a href=\"http:\/\/www.python.ambitious-engineer.com\/archives\/676\">\u300c\u30ea\u30b9\u30c8\u3092\u30ab\u30f3\u30de\u533a\u5207\u308a\u306e\u6587\u5b57\u5217\u306b\u5909\u63db\u3059\u308b\u300d<\/a>\u3068\u3044\u3046TIPS\u306b\u3001\u5b9f\u7528\u4e0a\u3088\u304f\u4f7f\u7528\u3059\u308b\u4f8b\u3092\u66f8\u304d\u307e\u3057\u305f\u3002\u53c2\u8003\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>map\u95a2\u6570\u3068\u306f map\u95a2\u6570\u306f\u30ea\u30b9\u30c8\u306a\u3069\u306e\u30a4\u30c6\u30e9\u30d6\u30eb\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306a\u5909\u6570\u306b\u5bfe\u3057\u3001\u305d\u306e\u5168\u3066\u306e\u8981\u7d20\u306b\u6307\u5b9a\u3057\u305f\u95a2\u6570\u3092\u5b9f\u884c\u3057\u3001\u7d50\u679c\u3092map\u578b\u3068\u547c\u3070\u308c\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u8fd4\u5374\u3057\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u5f15\u6570\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u304a\u305d\u3089\u304f\u3053\u308c\u3060\u3051\u3060\u3068\u4f55\u306e\u3053\u3068\u304b\u308f...<\/p>\n","protected":false},"author":1,"featured_media":3595,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[214,136],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/670"}],"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=670"}],"version-history":[{"count":10,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/670\/revisions"}],"predecessor-version":[{"id":687,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/670\/revisions\/687"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media\/3595"}],"wp:attachment":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media?parent=670"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/categories?post=670"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/tags?post=670"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}