{"id":1407,"date":"2020-06-02T00:00:00","date_gmt":"2020-06-01T15:00:00","guid":{"rendered":"https:\/\/www.ishikawasekkei.com\/?p=1407"},"modified":"2020-06-01T23:49:50","modified_gmt":"2020-06-01T14:49:50","slug":"python-dict-dictionary","status":"publish","type":"post","link":"https:\/\/www.ishikawasekkei.com\/index.php\/2020\/06\/02\/python-dict-dictionary\/","title":{"rendered":"Python\u30c7\u30a3\u30af\u30b7\u30e7\u30ca\u30ea\uff08\u8f9e\u66f8\uff09"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u3000\u4eca\u65e5\u3082\u898b\u306b\u6765\u3066\u4e0b\u3055\u3063\u3066\u3001\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\u3002\u77f3\u5ddd\u3055\u3093\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3000\u4eca\u65e5\u306f\u3001Python\u306e\u30c7\u30a3\u30af\u30b7\u30e7\u30ca\u30ea\u3092\u5c11\u3057\u7d39\u4ecb\u3057\u307e\u3059\u3002\u30c7\u30a3\u30af\u30b7\u30e7\u30ca\u30ea\u306f\u30ad\u30fc\u3068\u5024\u306e\u30da\u30a2\u3092\u683c\u7d0d\u3067\u304d\u308b\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3067\u3059\u3002\u306f\u3058\u3081\u3066\u3053\u306e\u30c7\u30a3\u30af\u30b7\u30e7\u30ca\u30ea\u3092\u77e5\u3063\u305f\u6642\u306f\u3001\u4fbf\u5229\u3059\u304e\u3066\u885d\u6483\u3067\u3057\u305f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f5c\u6210\u65b9\u6cd5\u3068\u4f7f\u3044\u65b9<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">In [1]: d = { \"A\": \"Apple\", \"B\": \"Boy\", \"C\": \"Color\" }\n\nIn [2]: d\nOut[2]: {'A': 'Apple', 'B': 'Boy', 'C': 'Color'}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u3000\u30c7\u30a3\u30af\u30b7\u30e7\u30ca\u30ea\u3092\u4f5c\u308b\u306b\u306f\u3001\u4e0a\u8a18\u306e\u3088\u3046\u306b\u30ad\u30fc\uff1a\u5024\u306e\u30da\u30a2\u3092\u30ab\u30f3\u30de\u3067\u533a\u5207\u3063\u3066\u4e26\u3079\u3001\u6ce2\u62ec\u5f27\u300c{}\u300d\u3067\u56f2\u307f\u307e\u3059\u3002\u305d\u308c\u305e\u308c\u306e\u8981\u7d20\u3092\u53d6\u308a\u51fa\u3059\u306b\u306f\u3001\u30ad\u30fc\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u6307\u5b9a\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">In [3]: d[\"A\"]\nOut[3]: 'Apple'\n\nIn [4]: d[\"B\"]\nOut[4]: 'Boy'\n\nIn [5]: d[\"C\"]\nOut[5]: 'Color'<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u3000\u30ad\u30fc\u3060\u3051\u3092\u53d6\u308a\u51fa\u3059\u3001\u5024\u3060\u3051\u3092\u53d6\u308a\u51fa\u3059\u3001\u30ad\u30fc\u3068\u5024\u306e\u30da\u30a2\u3092\u53d6\u308a\u51fa\u3059\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">In [6]: d.keys()\nOut[6]: dict_keys(['A', 'B', 'C'])\n\nIn [7]: d.values()\nOut[7]: dict_values(['Apple', 'Boy', 'Color'])\n\nIn [8]: d.items()\nOut[8]: dict_items([('A', 'Apple'), ('B', 'Boy'), ('C', 'Color')])<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u3000\u3061\u306a\u307f\u306b\u3001\u5b58\u5728\u3057\u306a\u3044\u30ad\u30fc\u3092\u6307\u5b9a\u3059\u308b\u3068\u3001\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">In [9]: d['Z']\nTraceback (most recent call last):\n\n  File \"&lt;ipython-input-168-b7ca268d4341>\", line 1, in &lt;module>\n    d['Z']\n\nKeyError: 'Z'\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u3000\u3053\u306e\u30ad\u30fc\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u306f\u3001in\u3092\u4f7f\u3063\u3066\u78ba\u8a8d\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">In [10]: 'A' in d\nOut[10]: True\n\nIn [11]: 'Z' in d\nOut[11]: False<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u3000\u5024\u3092\u5909\u66f4\u3059\u308b\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">In [12]: d['A'] = 'Air'\n\nIn [13]: d\nOut[13]: {'A': 'Air', 'B': 'Boy', 'C': 'Color'}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u3000\u5b58\u5728\u3057\u306a\u3044\u30ad\u30fc\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u8981\u7d20\u304c\u8ffd\u52a0\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">In [14]: d['D'] = 'Dictionary'\n\nIn [15]: d\nOut[15]: {'A': 'Air', 'B': 'Boy', 'C': 'Color', 'D': 'Dictionary'}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u3000\u8981\u7d20\u3092\u524a\u9664\u3059\u308b\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">In [16]: del d['C']\n\nIn [17]: d\nOut[17]: {'A': 'Air', 'B': 'Boy', 'D': 'Dictionary'}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u3000\u3059\u3079\u3066\u306e\u5024\u3092\u524a\u9664\u3059\u308b\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">In [18]: d.clear()\n\nIn [19]: d\nOut[19]: {}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u3000\u3053\u3053\u3067\u3001\u300c{}\u300d\u304c\u51fa\u3066\u307e\u3044\u308a\u307e\u3057\u305f\u304c\u3002\u7a7a\u306e\u30c7\u30a3\u30af\u30b7\u30e7\u30ca\u30ea\u3092\u4f5c\u6210\u3059\u308b\u3068\u304d\u306b\u3082\u300c{}\u300d\u304c\u4f7f\u3048\u307e\u3059\u3002\u306a\u306e\u3067\u3001\u3059\u3079\u3066\u306e\u5024\u3092\u524a\u9664\u3059\u308b\u3082\u3046\u4e00\u3064\u306e\u3084\u308a\u65b9\u3068\u3057\u3066\u3001\u7a7a\u8f9e\u66f8\u300c{}\u300d\u3092\u30c7\u30a3\u30af\u30b7\u30e7\u30ca\u30ea\u540d\u306b\u4ee3\u5165\u3059\u308b\u3053\u3068\u3067\u5b9f\u73fe\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3000\u307b\u304b\u306e\u30c7\u30a3\u30af\u30b7\u30e7\u30ca\u30ea\u306e\u4f5c\u6210\u65b9\u6cd5\u3068\u3057\u3066\u306f\u3001dict()\u304c\u4f7f\u3048\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">In [20]: dict()\nOut[20]: {}\n\nIn [21]: dict(['ab','cd','ef')\nOut[21]: {'a': 'b', 'c': 'd', 'e': 'f'}\n\nIn [22]: dict((['a','b'],['c','d'],['e','f']))\nOut[22]: {'a': 'b', 'c': 'd', 'e': 'f'}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u3000\u3053\u306e\u4ed6\u306b\u3082\u3001\u30bf\u30d7\u30eb\u3084\u30ea\u30b9\u30c8\u306e\u7d44\u307f\u5408\u308f\u305b\u304c\u5229\u7528\u53ef\u80fd\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3000\u5024\u3092\u53d6\u308a\u51fa\u3059\u4ed6\u306e\u3084\u308a\u65b9\u3068\u3057\u3066\u306f\u3001get()\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">In [23]: d.get('A')\n\nIn [24]: print(d.get('A'))\nNone\n\nIn [25]: d.get('A','a')\nOut[25]: 'a'\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u3000\u6700\u521d\u306e\u4f8b\u306f\u3001\u30ad\u30fc\u300c&#8217;A&#8217;\u300d\u306e\u5024\u3092\u53d6\u308a\u51fa\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u5b58\u5728\u3057\u306a\u3044\u305f\u3081\u3001None\u3092\u623b\u3057\u3066\u3044\u307e\u3059\u3002\u30a4\u30f3\u30bf\u30fc\u30d7\u30ea\u30bf\u30fc\u3067\u306f\u4f55\u3082\u8868\u793a\u3055\u308c\u306a\u3044\u305f\u3081\u3001print()\u3092\u4f7f\u3063\u3066\u78ba\u8a8d\u3057\u3066\u3044\u307e\u3059\u3002\u305d\u306e\u6b21\u306e\u4f8b\u306f\u3001\u5024\u304c\u306a\u304b\u3063\u305f\u6642\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u3068\u3057\u3066\u300c&#8217;a&#8217;\u300d\u3092\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u307e\u3068\u3081<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u3000\u30c7\u30a3\u30af\u30b7\u30e7\u30ca\u30ea\u306f\u3001\u3068\u3066\u3082\u4fbf\u5229\u3067\u3059\u306d\u3002\u9023\u7d9a\u3067\u53d6\u308a\u51fa\u3059\u3068\u304d\u306e\u9806\u756a\u306f\u4fdd\u8a3c\u3055\u308c\u307e\u305b\u3093\u306e\u3067\u3001\u305d\u3053\u3060\u3051\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3057\u3087\u3046\u304b\u3002\uff08\u9806\u756a\u3092\u4fdd\u8a3c\u3057\u305f\u3044\u5834\u5408\u306fOrderedDict()\u304c\u5229\u7528\u3067\u304d\u307e\u3059\u3002\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000\u4eca\u65e5\u3082\u898b\u306b\u6765\u3066\u4e0b\u3055\u3063\u3066\u3001\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\u3002\u77f3\u5ddd\u3055\u3093\u3067\u3059\u3002 \u3000\u4eca\u65e5\u306f\u3001Python\u306e\u30c7\u30a3\u30af\u30b7\u30e7\u30ca\u30ea\u3092\u5c11\u3057\u7d39\u4ecb\u3057\u307e\u3059\u3002\u30c7\u30a3\u30af\u30b7\u30e7\u30ca\u30ea\u306f\u30ad\u30fc\u3068\u5024\u306e\u30da\u30a2\u3092\u683c\u7d0d\u3067\u304d\u308b\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3067\u3059\u3002\u306f\u3058\u3081\u3066\u3053\u306e\u30c7\u30a3\u30af\u30b7\u30e7\u30ca\u30ea\u3092\u77e5\u3063\u305f\u6642\u306f\u3001 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.ishikawasekkei.com\/index.php\/2020\/06\/02\/python-dict-dictionary\/\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Python\u30c7\u30a3\u30af\u30b7\u30e7\u30ca\u30ea\uff08\u8f9e\u66f8\uff09&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,2],"tags":[],"class_list":["post-1407","post","type-post","status-publish","format-standard","hentry","category-program","category-blog"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/posts\/1407","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/comments?post=1407"}],"version-history":[{"count":1,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/posts\/1407\/revisions"}],"predecessor-version":[{"id":1408,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/posts\/1407\/revisions\/1408"}],"wp:attachment":[{"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/media?parent=1407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/categories?post=1407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/tags?post=1407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}