{"id":3392,"date":"2026-11-27T13:16:25","date_gmt":"2026-11-27T04:16:25","guid":{"rendered":"https:\/\/danlabs.kr\/?p=3392"},"modified":"2026-11-27T13:16:49","modified_gmt":"2026-11-27T04:16:49","slug":"python-counter-stock-difference","status":"publish","type":"post","link":"https:\/\/danlabs.kr\/?p=3392","title":{"rendered":"Python Counter\ub85c \uc7ac\uace0 \ub300\uc870\ud558\uae30: \ube84\uc148\uacfc subtract\uc758 \ucc28\uc774"},"content":{"rendered":"<p>Python\uc758 <code>Counter<\/code>\ub85c <code>\uc2e4\uc0ac - \uc7a5\ubd80<\/code>\ub97c \uacc4\uc0b0\ud558\uba74 \ucd08\uacfc\ubd84\ub9cc \ub0a8\uace0, \uc218\ub7c9\uc774 \ubaa8\uc790\ub780 \ud488\ubaa9\uc740 \uacb0\uacfc\uc5d0\uc11c \uc0ac\ub77c\uc838\uc694<sup><a href=\"#source-1\">[1]<\/a><\/sup>. \ubd80\uc871\uc744 \ub73b\ud558\ub294 \uc74c\uc218\uae4c\uc9c0 \uae30\ub85d\ud558\ub824\uba74 \ube84\uc148 \uc5f0\uc0b0\uc790 \ub300\uc2e0 <code>subtract()<\/code>\ub97c \uc368\uc694<sup><a href=\"#source-1\">[1]<\/a><\/sup>.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-counter-stock-20261127-inline1.jpg\" alt=\"\uc218\ub7c9 \uc9d1\uacc4\uc640 \uc911\ubcf5 \uc81c\uac70\ub97c \ub098\ub780\ud788 \ube44\uad50\ud55c \uc0dd\uc131 \ub3c4\uc2dd\" width=\"1280\" height=\"720\" loading=\"lazy\"><\/figure>\n<h2>\ubd80\ud488\uc774 \uc788\ub2e4\ub294 \uac83\uacfc \uba87 \uac1c \uc788\ub2e4\ub294 \uac83\uc740 \ub2ec\ub77c\uc694<\/h2>\n<p>\ubd80\ud488 \uc2a4\uce94 \ubaa9\ub85d\uc744 <code>set<\/code>\uc5d0 \ub123\uc73c\uba74 \uc5b4\ub5a4 \ud488\ubaa9\uc774 \uc788\ub294\uc9c0 \uc54c \uc218 \uc788\uc9c0\ub9cc, \uac19\uc740 \ubd80\ud488\uc744 \uba87 \ubc88 \uc2a4\uce94\ud588\ub294\uc9c0\ub294 \ub0a8\uc9c0 \uc54a\uc544\uc694<sup><a href=\"#source-2\">[2]<\/a><\/sup>. <code>Counter<\/code>\ub294 \ud488\ubaa9 \ucf54\ub4dc\ub97c \ud0a4\ub85c, \ub4f1\uc7a5 \ud69f\uc218\ub97c \uac12\uc73c\ub85c \ubcf4\uad00\ud574\uc694<sup><a href=\"#source-1\">[1]<\/a><\/sup>.<\/p>\n<p>\uc7a5\ubd80\ucc98\ub7fc \ud488\ubaa9\ubcc4 \uc218\ub7c9\uc774 \uc774\ubbf8 \uacc4\uc0b0\ub41c \uc785\ub825\uc740 <code>Counter({'blue': 1})<\/code>\ucc98\ub7fc \ub9e4\ud551\uc73c\ub85c, \uc2a4\uce94 \ubaa9\ub85d\uc740 <code>Counter(['blue'])<\/code>\ucc98\ub7fc \ud488\ubaa9\uc774 \ub2f4\uae34 \ub9ac\uc2a4\ud2b8\ub85c \ub118\uaca8\uc694<sup><a href=\"#source-1\">[1]<\/a><\/sup>. \ubb38\uc790\uc5f4\uc744 <code>Counter('blue')<\/code>\ucc98\ub7fc \ubc14\ub85c \ub118\uae30\uba74 \ud488\ubaa9 \ud558\ub098 \ub300\uc2e0 \ubb38\uc790\uc5f4\uc744 \uc774\ub8e8\ub294 \ubb38\uc790\ub97c \ud558\ub098\uc529 \uc138\ubbc0\ub85c, \ud488\ubaa9 \ucf54\ub4dc \ub2e8\uc704\ub85c \ubb36\uc5b4 \uac74\ub124\uc694<sup><a href=\"#source-1\">[1]<\/a><\/sup>.<\/p>\n<h2>\ucd08\uacfc\ubd84\uacfc \ubd80\uc871\ubd84\uc744 \ubcc4\ub3c4 \ubaa9\ub85d\uc73c\ub85c \ubf51\uae30<\/h2>\n<p>\uc544\ub798 \uc608\uc5d0\uc11c \uc7a5\ubd80\uc5d0\ub294 \ud30c\ub791 \ubd80\ud488 1\uac1c, \ucd08\ub85d 2\uac1c, \ud68c\uc0c9 1\uac1c\uac00 \uc788\uc5b4\uc57c \ud558\uace0, \uc2e4\uc0ac \ubaa9\ub85d\uc5d0\ub294 \ucd08\ub85d\u00b7\ud68c\uc0c9\u00b7\ub178\ub791\uc774 \ud558\ub098\uc529 \uc788\uc5b4\uc694. <code>Counter<\/code>\uc5d0\uc11c \uc5c6\ub294 \ud0a4\ub97c \ub300\uad04\ud638\ub85c \uc77d\uc73c\uba74 0\uc774\ubbc0\ub85c, \ub178\ub791\uc740 \uc7a5\ubd80 \uc218\ub7c9\uc774 0\uc774\uace0 \ud30c\ub791\uc740 \uc2e4\uc0ac \uc218\ub7c9\uc774 0\uc778 \uc148\uc774\uc5d0\uc694<sup><a href=\"#source-1\">[1]<\/a><\/sup>.<\/p>\n<p><code>actual - expected<\/code>\ub294 \uc2e4\uc0ac\uac00 \uc7a5\ubd80\ubcf4\ub2e4 \ub9ce\uc740 \ud488\ubaa9\ub9cc \ub0a8\uaca8\uc694<sup><a href=\"#source-1\">[1]<\/a><\/sup>. \ubc18\ub300\ub85c <code>expected - actual<\/code>\uc744 \uacc4\uc0b0\ud558\uba74 \ubd80\uc871\ud55c \ud488\ubaa9\uacfc \ubd80\uc871 \uc218\ub7c9\uc744 \uc591\uc218\ub85c \uc5bb\uc5b4\uc694<sup><a href=\"#source-1\">[1]<\/a><\/sup>. \uac19\uc740 \ud488\ubaa9\ub07c\ub9ac \uc218\ub7c9\uc744 \ube80 \ub4a4 0 \uc774\ud558\ub97c \ubc84\ub9ac\ub294 \uaddc\uce59\uc740 \ub450 \ubc29\ud5a5 \ubaa8\ub450 \uac19\uc544\uc694<sup><a href=\"#source-1\">[1]<\/a><\/sup>.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-counter-stock-20261127-inline2.jpg\" alt=\"\ucd08\uacfc\uc640 \ubd80\uc871\uc744 \uac01\uac01 \ub3c5\ub9bd\ub41c \uce74\ub4dc\ub85c \ud45c\uc2dc\ud55c \uc0dd\uc131 \ub3c4\uc2dd\" width=\"1280\" height=\"720\" loading=\"lazy\"><\/figure>\n<h2>\ubd80\ud638\ub97c \ub0a8\uae30\ub294 \ucabd\uc740 \ubcf5\uc0ac\ubcf8\uc5d0\uc11c \uacc4\uc0b0\ud574\uc694<\/h2>\n<p><code>subtract()<\/code>\ub294 \ud638\ucd9c\ud55c <code>Counter<\/code>\uc758 \uc218\ub7c9\uc744 \ubc14\uafb8\uba70 \uacc4\uc0b0 \uacb0\uacfc\uc5d0 0\uacfc \uc74c\uc218\ub97c \ub0a8\uae38 \uc218 \uc788\uc5b4\uc694<sup><a href=\"#source-1\">[1]<\/a><\/sup>. \uadf8\ub798\uc11c \uc6d0\ub798 \uc2e4\uc0ac \uc9d1\uacc4\ub3c4 \ub4a4\uc5d0\uc11c \uc4f0\ub824\uba74 <code>actual.copy()<\/code>\ub85c \ubcf5\uc0ac\ubcf8\uc744 \ub9cc\ub4e4\uc5b4 \uc7a5\ubd80 \uc218\ub7c9\uc744 \ube7c\uc694<sup><a href=\"#source-1\">[1]<\/a><\/sup>.<\/p>\n<pre><code class=\"language-python\">from collections import Counter\n\nexpected = Counter({'blue': 1, 'green': 2, 'gray': 1})\nactual = Counter(['green', 'gray', 'yellow'])\n\nsurplus = actual - expected\nshortage = expected - actual\nsigned = actual.copy()\nsigned.subtract(expected)\n\nprint('surplus:', dict(sorted(surplus.items())))\nprint('shortage:', dict(sorted(shortage.items())))\nprint('signed:', dict(sorted(signed.items())))<\/code><\/pre>\n<pre><code class=\"language-text\">surplus: {'yellow': 1}\nshortage: {'blue': 1, 'green': 1}\nsigned: {'blue': -1, 'gray': 0, 'green': -1, 'yellow': 1}<\/code><\/pre>\n<p>Python 3.14.9\uc5d0\uc11c \uc704 \ucf54\ub4dc\ub97c \uadf8\ub300\ub85c \uc2e4\ud589\ud55c \uacb0\uacfc\uc608\uc694. \ud68c\uc0c9\uc740 \ub450 \uc218\ub7c9\uc774 \uac19\uc544\uc11c \ucd08\uacfc\u00b7\ubd80\uc871 \ubaa9\ub85d\uc5d0\ub294 \uc5c6\uace0 <code>signed<\/code>\uc5d0\ub9cc <code>0<\/code>\uc73c\ub85c \ub0a8\uc544\uc694. <code>Counter<\/code>\uc5d0\uc11c \uae30\uc874 \uc218\ub7c9\uc744 0\uc73c\ub85c \ub9de\ucdb0\ub3c4 \ud0a4\ub294 \uc790\ub3d9 \uc0ad\uc81c\ub418\uc9c0 \uc54a\uc73c\ubbc0\ub85c, \uc218\ub7c9\uc774 0\uc778 \ud0a4\ub97c \uac16\uace0 \uc788\ub294 \uac83\uacfc \ud0a4\uac00 \uc544\uc608 \uc5c6\ub294 \uac83\uc740 \ub2ec\ub77c\uc694<sup><a href=\"#source-1\">[1]<\/a><\/sup>.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-counter-stock-20261127-inline3.jpg\" alt=\"\uc591\uc218\ub9cc \ub0a8\uae30\ub294 \uacc4\uc0b0\uacfc \ubd80\ud638\ub97c \ubcf4\uc874\ud558\ub294 \uae30\ub85d\uc744 \ube44\uad50\ud55c \uc0dd\uc131 \ub3c4\uc2dd\" width=\"1280\" height=\"720\" loading=\"lazy\"><\/figure>\n<h2>\ub300\uc870 \uacb0\uacfc\ub97c \uc5b4\ub290 \ud654\uba74\uc5d0 \ubcf4\ub0bc\uc9c0\uac00 \uae30\uc900\uc774\uc5d0\uc694<\/h2>\n<p>\uc785\uace0 \ub2f4\ub2f9\uc790\uac00 \ucd08\uacfc \uc218\ub7c9\uc744 \ucc3e\uace0 \ubcf4\ucda9 \ub2f4\ub2f9\uc790\uac00 \ubd80\uc871 \uc218\ub7c9\uc744 \ucc3e\ub294 \ud654\uba74\uc774\ub77c\uba74 \ubc29\ud5a5\uc744 \ubc14\uafd4 \ube80 \ub450 \ubaa9\ub85d\uc774 \uc77d\uae30 \uc26c\uc6cc\uc694. \ub300\uc870 \uae30\ub85d\uc744 \ubcf4\uad00\ud560 \ub54c\ub294 <code>\uc2e4\uc0ac - \uc7a5\ubd80<\/code>\ucc98\ub7fc \uacc4\uc0b0 \ubc29\ud5a5\uc744 \ud544\ub4dc \uc606\uc5d0 \ub0a8\uaca8\uc57c, \ub4a4\uc5d0 \uae30\ub85d\uc744 \uc77d\ub294 \uc0ac\ub78c\ub3c4 <code>-1<\/code>\uc744 \ubd80\uc871 \ud55c \uac1c\ub85c \uc77d\uc744 \uc218 \uc788\uc5b4\uc694.<\/p>\n<p>\ud30c\uc77c\uc5d0\uc11c \uc7a5\ubd80\ub97c \ubd88\ub7ec\uc628\ub2e4\uba74 <a href=\"https:\/\/danlabs.kr\/?p=3137\">Python <code>csv.DictReader<\/code>\uc5d0\uc11c \ub204\ub77d\ub41c \uc5f4\uacfc \uac12 \uad6c\ubd84\ud558\uae30<\/a>\ucc98\ub7fc, \uc9d1\uacc4 \uc804\uc5d0 \ud488\ubaa9 \ucf54\ub4dc\uc640 \uc218\ub7c9 \uc5f4\ubd80\ud130 \uc77d\ub294 \ub2e8\uacc4\uac00 \ub530\ub85c \uc788\uc5b4\uc694. \uc5ec\uae30\uc11c \ube60\uc9c4 \uc785\ub825 \ud589\uc744 <code>Counter<\/code>\uc758 \uae30\ubcf8\uac12 0\uc73c\ub85c \ub36e\uc5b4 \ubc84\ub9ac\uba74, \uc815\ub9d0 0\uac1c\uc778 \ud488\ubaa9\uacfc \uc77d\uc9c0 \ubabb\ud55c \ud488\ubaa9\uc774 \uac19\uc740 \uc22b\uc790\ub85c \ubcf4\uc77c \uc218 \uc788\uc5b4\uc694<sup><a href=\"#source-1\">[1]<\/a><\/sup>.<\/p>\n<p><em>\ub300\ud45c \ubc0f \ubcf8\ubb38 \uadf8\ub9bc\uc740 \uc0dd\uc131 \uac1c\ub150 \uc774\ubbf8\uc9c0\uc608\uc694.<\/em><\/p>\n<p><strong>Sources<\/strong><\/p>\n<ol>\n<li id=\"source-1\"><a href=\"https:\/\/docs.python.org\/3.14\/library\/collections.html\" target=\"_blank\" rel=\"noopener noreferrer\">Python 3.14 \uacf5\uc2dd \ubb38\uc11c \u2014 collections.Counter (2026-11-27 \uc870\ud68c)<\/a><\/li>\n<li id=\"source-2\"><a href=\"https:\/\/docs.python.org\/3.14\/tutorial\/datastructures.html\" target=\"_blank\" rel=\"noopener noreferrer\">Python 3.14 \uacf5\uc2dd \ud29c\ud1a0\ub9ac\uc5bc \u2014 Sets (2026-11-27 \uc870\ud68c)<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Python Counter\ub85c \uc2e4\uc0ac\uc640 \uc7a5\ubd80\uc758 \uc7ac\uace0\ub97c \ube44\uad50\ud574\uc694. \ube84\uc148\uc73c\ub85c \ucd08\uacfc\u00b7\ubd80\uc871 \ubaa9\ub85d\uc744 \ub9cc\ub4e4\uace0, subtract()\ub85c \uc74c\uc218\uc640 0\uc744 \ub0a8\uae30\ub294 \ucc28\uc774\ub97c \uc2e4\ud589 \uc608\uc81c\ub85c \ud655\uc778\ud574\uc694.<\/p>\n","protected":false},"author":1,"featured_media":3388,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-3392","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dev"],"featured_image_urls":{"full":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-counter-stock-20261127-feat.jpg",1280,720,false],"thumbnail":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-counter-stock-20261127-feat-150x150.jpg",150,150,true],"medium":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-counter-stock-20261127-feat-300x169.jpg",300,169,true],"medium_large":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-counter-stock-20261127-feat-768x432.jpg",640,360,true],"large":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-counter-stock-20261127-feat-1024x576.jpg",640,360,true],"1536x1536":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-counter-stock-20261127-feat.jpg",1280,720,false],"2048x2048":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-counter-stock-20261127-feat.jpg",1280,720,false],"morenews-large":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-counter-stock-20261127-feat-825x575.jpg",825,575,true],"morenews-medium":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-counter-stock-20261127-feat-590x410.jpg",590,410,true],"danlabs-list-small":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-counter-stock-20261127-feat-366x190.jpg",366,190,true],"danlabs-list-retina":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-counter-stock-20261127-feat.jpg",1280,720,false]},"author_info":{"display_name":"DanLABs","author_link":"https:\/\/danlabs.kr\/author\/hello-danlabs-kr"},"category_info":"<a href=\"https:\/\/danlabs.kr\/?cat=19\" rel=\"category\">\uac1c\ubc1c<\/a>","tag_info":"\uac1c\ubc1c","comment_count":"0","_links":{"self":[{"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/posts\/3392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/danlabs.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3392"}],"version-history":[{"count":1,"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/posts\/3392\/revisions"}],"predecessor-version":[{"id":3393,"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/posts\/3392\/revisions\/3393"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/media\/3388"}],"wp:attachment":[{"href":"https:\/\/danlabs.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/danlabs.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/danlabs.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}