{"id":11462,"date":"2017-09-11T14:54:33","date_gmt":"2017-09-11T05:54:33","guid":{"rendered":"http:\/\/sitest.jp\/blog\/?p=11462"},"modified":"2017-09-11T14:54:33","modified_gmt":"2017-09-11T05:54:33","slug":"python-%e3%81%ae%e3%83%aa%e3%82%b9%e3%83%88%e5%87%a6%e7%90%86%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6%e3%80%81%e3%81%be%e3%81%a8%e3%82%81%e3%81%be%e3%81%97%e3%81%9f%e3%80%82%e2%80%95for-%e6%96%87%e3%80%81","status":"publish","type":"post","link":"https:\/\/sitest.jp\/blog\/?p=11462","title":{"rendered":"Python \u306e\u30ea\u30b9\u30c8\u51e6\u7406\u306b\u3064\u3044\u3066\u3001\u307e\u3068\u3081\u307e\u3057\u305f\u3002\u2015for \u6587\u3001\u7d44\u307f\u8fbc\u307f\u95a2\u6570(map)\u3001\u5185\u5305\u8868\u8a18\u2015"},"content":{"rendered":"<p>Java \u306a\u3069\u306e\u4ed6\u306e\u8a00\u8a9e\u306b\u6163\u308c\u3066\u304b\u3089 Python \u3092\u59cb\u3081\u308b\u3068\u3001\u306f\u3058\u3081\u306f\u30b7\u30f3\u30d7\u30eb\u306a\u69cb\u6587\u3082\u3042\u3063\u3066\u3001\u30b5\u30af\u30b5\u30af\u66f8\u3051\u308b\u306e\u3067\u3059\u304c\u3001\u3075\u3068\u3057\u305f\u3068\u3053\u308d\u3067\u3064\u307e\u3065\u304d\u304c\u3042\u308a\u307e\u3059\u3002\u79c1\u306b\u3068\u3063\u3066\u3001\u305d\u308c\u306f\u30ea\u30b9\u30c8\u51e6\u7406\u3067\u3057\u305f\u3002Python \u3067\u30ea\u30b9\u30c8\u306e\u4e2d\u8eab\u3092\u51e6\u7406\u3057\u305f\u3044\u3051\u3069\u3084\u308a\u65b9\u304c\u305f\u304f\u3055\u3093\u3042\u308a\u3059\u304e\u308b\u2026\u666e\u901a\u306f for \u30eb\u30fc\u30d7\u3067\u3044\u3044\u3093\u3060\u308d\u3046\u3051\u3069\u3001\u5185\u5305\u8868\u8a18\u3068\u304b\u3001map \u3068\u304b\u3044\u308d\u3044\u308d\u3042\u3063\u3066\u3001\u3069\u308c\u3092\u4f7f\u3048\u3070\u3044\u3044\u306e\u304b\u308f\u304b\u3089\u306a\u3044\u2026\u306a\u306e\u3067\u3001\u8abf\u3079\u3066\u307f\u307e\u3057\u305f\u3002\u8abf\u3079\u305f\u306e\u306f Python3.x \u3067\u3059\u3002<br \/>\n<!--more--><\/p>\n<div class=\"frame_headding\">\n<h3 style=\"text-align: left;\">\nfor \u6587<br \/>\n<\/h3>\n<\/div>\n<p>\u304a\u306a\u3058\u307f\u306e for \u6587\u3067\u3059\u3002\u4ed6\u306e\u591a\u304f\u306e\u8a00\u8a9e\u3068\u540c\u3058\u3088\u3046\u306b\u5229\u7528\u3067\u304d\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002{}\u306a\u3069\u3067\u56f2\u3080\u3053\u3068\u306a\u304f\u3001\u30a4\u30f3\u30c7\u30f3\u30c8\u3067\u30eb\u30fc\u30d7\u3092\u8a18\u8ff0\u3067\u304d\u308b\u306e\u306f\u3046\u308c\u3057\u3044\u3067\u3059\u306d\u3002for&#8230;in \u6587\u3067\u30ea\u30b9\u30c8\u306e\u4e2d\u8eab\u3059\u3079\u3066\u3092\u51e6\u7406\u3067\u304d\u307e\u3059<\/p>\n<pre><code>foods = ['ham', 'egg', 'spam']\ndishes = []\n\nfor food in foods:\n    dishes.append(food + '_spam')\n\nprint(dishes)\n\n\u7d50\u679c: ['ham_spam', 'egg_spam', 'spam_spam']\n<\/code><\/pre>\n<div class=\"frame_headding\">\n<h3 style=\"text-align: left;\">\n\u5185\u5305\u8868\u8a18<br \/>\n<\/h3>\n<\/div>\n<p>Python \u306e\u5fc3\u69cb\u3048\u3092\u793a\u3057\u305f\u300cZen of Python\u300d\u306b\u300cFlat is better than nested.(\u5165\u308c\u5b50\u3088\u308a\u30d5\u30e9\u30c3\u30c8\u306e\u307b\u3046\u304c\u3088\u3044)\u300d\u3068\u3044\u3046\u3082\u306e\u304c\u3042\u308a\u307e\u3059\u3002\u5185\u5305\u8868\u8a18\u306f\u305d\u306e\u3088\u3046\u306a\u8003\u3048\u306e\u3082\u3068\u30a4\u30f3\u30c7\u30f3\u30c8\u3092\u4f7f\u308f\u305a\u306b\u3001\u30ea\u30b9\u30c8\u51e6\u7406\u3092\u3059\u308b\u3082\u306e\u3067\u3059\u3002\u898b\u305f\u76ee\u8907\u96d1\u3067\u3059\u304c\u3001\u51e6\u7406\u3092\u9806\u756a\u306b\u66f8\u3044\u3066\u3044\u304f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u6587\u3067\u306f\u306a\u304f\u3001\u666e\u901a\u306e\u82f1\u8a9e\u306e\u3088\u3046\u306b\u8aad\u3093\u3067\u3044\u3051\u3070\u3044\u3044\u3053\u3068\u304c\u5206\u304b\u308a\u307e\u3057\u305f\u3002<\/p>\n<pre><code>foods = ['ham', 'egg', 'spam']\ndishes = [ food + '_spam' for food in foods ]\n\nprint(dishes)\n\n\u7d50\u679c: ['ham_spam', 'egg_spam', 'spam_spam']\n<\/code><\/pre>\n<p>\u4e0a\u8a18\u306e\u5834\u5408\u300cfood \u306b&#8217;_spam&#8217; \u3092\u9023\u7d50\u3059\u308b(\u51e6\u7406\u306e\u5185\u5bb9)\u3002 foods\u306e\u4e2d\u306bfood\u304c\u3042\u308b\u9650\u308a(\u6761\u4ef6)\u300d\u3068\u3044\u3046\u610f\u5473\u306b\u306a\u308a\u307e\u3059<\/p>\n<p>for \u30eb\u30fc\u30d7\u3067\u306f\u65b0\u305f\u306a\u914d\u5217 dishes \u3092\u4e88\u3081\u4f5c\u3063\u3066\u304a\u304d\u3001\u305d\u306e\u4e2d\u306b &#8216;_spam&#8217; \u3092\u52a0\u3048\u308b\u3001\u3068\u3044\u3046\u4e8c\u6bb5\u968e\u3092\u305f\u3069\u3063\u3066\u3044\u307e\u3057\u305f\u3002\u305d\u308c\u306b\u5bfe\u3057\u3066\u3001\u5185\u5305\u8868\u8a18\u306f\u914d\u5217\u81ea\u4f53\u3092\u4f5c\u308b\u306e\u3068\u3001\u305d\u306e\u4e2d\u8eab\u3092\u4f5c\u308b\u51e6\u7406\u3092\u540c\u6642\u306b\u884c\u3046\u3082\u306e\u3060\u3068\u89e3\u91c8\u3067\u304d\u307e\u3059\u3002<\/p>\n<div class=\"frame_headding\">\n<h3 style=\"text-align: left;\">\nmap \u95a2\u6570 + lambda<br \/>\n<\/h3>\n<\/div>\n<p>\u6700\u5f8c\u306f\u7d44\u307f\u8fbc\u307f\u95a2\u6570\u306e map \u3067\u3059\u3002\u5f15\u6570\u30922\u3064\u53d6\u308b\u95a2\u6570\u3067 \u300cmap(\u95a2\u6570,  \u30ea\u30b9\u30c8) \u300d\u3068\u3044\u3046\u3075\u3046\u306b\u4f7f\u3044\u307e\u3059\u3002\u95a2\u6570\u306e\u51e6\u7406\u5185\u5bb9\u3092\u30ea\u30b9\u30c8\u306e\u4e2d\u8eab\u3072\u3068\u3064\u3072\u3068\u3064\u306b\u9069\u7528\u3059\u308b\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u5f15\u6570\u3068\u3057\u3066\u6e21\u3059\u95a2\u6570\u306f\u3001\u5fc5\u305a\u5024\u3092\u8fd4\u3059\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre><code>def cook(food):\n    return food + '_spam'\nfoods = ['ham', 'egg', 'spam']\ndishes = map(cook, foods)\n<\/code><\/pre>\n<p>\u3055\u3066\u3001python \u306b\u306f lambda \u3068\u3044\u3046\u3001\u4e88\u3081\u95a2\u6570\u3092\u5b9a\u7fa9\u3057\u3066\u304a\u304b\u304f\u3066\u3082\u3001\u305d\u306e\u5834\u3067\u95a2\u6570\u3092\u5b9a\u7fa9\u3059\u308b\u6a5f\u80fd\u304c\u3042\u308a\u307e\u3059\u3002\u5b9a\u7fa9\u306f\u300clambda \u5f15\u6570:\u623b\u308a\u5024\u300d\u3068\u8a00\u3046\u304b\u305f\u3061\u3067\u884c\u3044\u307e\u3059\u3002\u305d\u3046\u3084\u3063\u3066\u4f5c\u3063\u305f\u95a2\u6570\u3092\u3001\u5909\u6570\u306b\u683c\u7d0d\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u4e0a\u306e\u30b3\u30fc\u30c9\u3092 lambda \u3092\u4f7f\u3063\u3066\u66f8\u304d\u76f4\u3059\u3068\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059<\/p>\n<pre><code>foods = ['ham', 'egg', 'spam']\ndishes = map(lambda str: str + '_spam', foods)\n<\/code><\/pre>\n<p>\u3055\u3066\u3001for \u6587\u3084\u5185\u5305\u8868\u8a18\u3067\u306e\u4f8b\u306e\u3088\u3046\u306b<\/p>\n<pre><code>print(dishes)\n<\/code><\/pre>\n<p>\u3068\u3057\u3066 \u30ea\u30b9\u30c8 dishes \u306e\u4e2d\u8eab\u3092\u51fa\u529b\u3057\u305f\u3044\u306e\u3067\u3059\u304c\u3001<\/p>\n<pre><code>&lt;map object at 0x10ee71908&gt;\n<\/code><\/pre>\n<p>\u306e\u3088\u3046\u306b\u8b0e\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u51fa\u529b\u3055\u308c\u307e\u3059\u3002\u3053\u308c\u306f iterator \u3068\u3044\u3046\u3082\u306e\u3067\u3001\u30ea\u30b9\u30c8\u51e6\u7406\u306f\u307e\u3060\u5b9f\u884c\u3055\u308c\u305a\u6e96\u5099\u6bb5\u968e\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u3057\u3066\u4fdd\u5b58\u3057\u3066\u3044\u308b\u3082\u306e\u3067\u3059\u3002\u30ea\u30b9\u30c8\u306e\u8981\u7d20\u6570\u304c\u3068\u3066\u3082\u591a\u3044\u6642\u3053\u308c\u3092\u3046\u307e\u304f\u4f7f\u3046\u3053\u3068\u3067\u3001\u51e6\u7406\u306e\u30bf\u30a4\u30df\u30f3\u30b0\u3092\u306f\u304b\u308a\u3001\u30e1\u30e2\u30ea\u3092\u7bc0\u7d04\u3059\u308b\u306a\u3069\u3067\u304d\u307e\u3059\u3002<br \/>\n\u51e6\u7406\u3092\u884c\u3044\u305f\u3044\u3068\u304d\u306f<\/p>\n<pre><code>list(dishes)\n<\/code><\/pre>\n<p>\u306a\u3069\u306e\u3088\u3046\u306b\u3001list \u95a2\u6570\u306b\u6e21\u3059\u306a\u3069\u3057\u307e\u3059\u3002\u306a\u306e\u3067\u3001\u7d50\u679c\u3092\u51fa\u529b\u3057\u305f\u3044\u3068\u304d\u306f<\/p>\n<pre><code>print(list(dishes))\n<\/code><\/pre>\n<p>\u306e\u3088\u3046\u306b\u66f8\u304d\u307e\u3059\u3002<br \/>\n\u4ee5\u4e0a python \u306e\u30ea\u30b9\u30c8\u51e6\u7406\u3092\u307e\u3068\u3081\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java \u306a\u3069\u306e\u4ed6\u306e\u8a00\u8a9e\u306b\u6163\u308c\u3066\u304b\u3089 Python \u3092\u59cb\u3081\u308b\u3068\u3001\u306f\u3058\u3081\u306f\u30b7\u30f3\u30d7\u30eb\u306a\u69cb\u6587\u3082\u3042\u3063\u3066\u3001\u30b5\u30af\u30b5\u30af\u66f8\u3051\u308b\u306e\u3067\u3059\u304c\u3001\u3075\u3068\u3057\u305f\u3068\u3053\u308d\u3067\u3064\u307e\u3065\u304d\u304c\u3042\u308a\u307e\u3059\u3002\u79c1\u306b\u3068\u3063\u3066\u3001\u305d\u308c\u306f\u30ea\u30b9\u30c8\u51e6\u7406\u3067\u3057\u305f\u3002Python \u3067\u30ea\u30b9\u30c8\u306e\u4e2d\u8eab\u3092\u51e6\u7406\u3057\u305f\u3044\u3051\u3069\u3084\u308a\u65b9\u304c\u305f\u304f\u3055\u3093\u3042\u308a\u3059\u304e\u308b\u2026\u666e\u901a\u306f for \u30eb\u30fc\u30d7\u3067\u3044\u3044\u3093\u3060\u308d\u3046\u3051\u3069\u3001\u5185\u5305\u8868\u8a18\u3068\u304b\u3001map \u3068\u304b\u3044\u308d\u3044\u308d\u3042\u3063\u3066\u3001\u3069\u308c\u3092\u4f7f\u3048\u3070\u3044\u3044\u306e\u304b\u308f\u304b\u3089\u306a\u3044\u2026\u306a\u306e\u3067\u3001\u8abf\u3079\u3066\u307f\u307e\u3057 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":11465,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[27],"tags":[],"acf":false,"_links":{"self":[{"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/posts\/11462"}],"collection":[{"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/comments?post=11462"}],"version-history":[{"count":4,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/posts\/11462\/revisions"}],"predecessor-version":[{"id":13013,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/posts\/11462\/revisions\/13013"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/media\/11465"}],"wp:attachment":[{"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/media?parent=11462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/categories?post=11462"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/tags?post=11462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}