{"id":377705,"date":"2024-06-01T15:00:28","date_gmt":"2024-06-01T15:00:28","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=377705"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=377705","title":{"rendered":"<span>\u042d\u0432\u043e\u043b\u044e\u0446\u0438\u044f \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 \u0432 Python<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0423 \u043e\u0434\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u044f. \u0412\u043e\u0437\u044c\u043c\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u2014\u00a0<strong>\u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430<\/strong>,<strong>\u00a0<\/strong>\u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0441\u0447\u0438\u0442\u0430\u0435\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441\u043f\u0438\u0441\u043a\u0430 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0435\u043c. \u0421\u043f\u043e\u0441\u043e\u0431 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430 Python \u043c\u0435\u043d\u044f\u043b\u0441\u044f \u043f\u043e \u043c\u0435\u0440\u0435 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044f \u044f\u0437\u044b\u043a\u0430. \u0418\u043c\u0435\u043d\u043d\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.<\/p>\n<p>\u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0438\u0437 \u043d\u0430\u0441 \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u043b\u043e\u0441\u044c \u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u043d\u0430 Python \u0441 \u0435\u0433\u043e \u0442\u0440\u0435\u0442\u044c\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438. \u041e\u0434\u043d\u0430\u043a\u043e \u043c\u044b \u043d\u0430\u0447\u043d\u0435\u043c \u0441 Python 1.4. \u041f\u0440\u0438\u0441\u0442\u0435\u0433\u043d\u0438\u0442\u0435 \u0440\u0435\u043c\u043d\u0438, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u0441\u044f \u0432 \u0434\u0430\u043b\u0435\u043a\u043e\u0435 \u043f\u0440\u043e\u0448\u043b\u043e\u0435 \u2014 \u0432 1997 \u0433\u043e\u0434!<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/294\/b80\/478\/294b80478c4750043f3efe0654c72f38.png\" width=\"1920\" height=\"1080\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/294\/b80\/478\/294b80478c4750043f3efe0654c72f38.png\"\/><\/figure>\n<h4>Python 1.4<\/h4>\n<p>\u041c\u0430\u043b\u043e \u043a\u0442\u043e \u043f\u043e\u043c\u043d\u0438\u0442 \u044d\u0442\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0430. \u042d\u0442\u043e \u0434\u0430\u0436\u0435 \u043d\u0435 Python 2. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0443\u0436\u0435 \u0432 \u044d\u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u044f\u0437\u044b\u043a\u0430 \u0431\u044b\u043b\u0438 \u0441\u043b\u043e\u0432\u0430\u0440\u0438 \u2014 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445\u00a0<code>dict<\/code>.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">letters = ['a', 'b', 'c', 'a', 'c', 'a', 't', 'p', 'b', 'a', 'y', 't', 'c'] letter_counts = {}  for char in letters:     if letter_counts.has_key(char):         letter_counts[char] = letter_counts[char] + 1     else:         letter_counts[char] = 1          print letter_counts<\/code><\/pre>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u0442 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f):<\/p>\n<pre><code class=\"markdown\">{'a': 4, 'b': 2, 'c': 3, 't': 2, 'p': 1, 'y': 1}<\/code><\/pre>\n<p>\u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c \u0432\u044b\u0448\u0435 \u043a\u043e\u0434\u0435 \u043c\u044b \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a\u00a0<code>letters<\/code>\u00a0\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043d\u0430 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0435\u0433\u043e \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u00a0<code>letter_counts<\/code>. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u043c\u044b \u0435\u0433\u043e \u0442\u0443\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c, \u0430 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u0435\u0433\u043e \u0441\u0447\u0435\u0442\u0447\u0438\u043a.<\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0432 Python 1.4 \u0432\u043c\u0435\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e\u0433\u043e \u043d\u0430\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u0438\u00a0<code>in<\/code>\u00a0(\u043e\u043d \u0431\u044b\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0432 Python 2.2) \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434\u00a0<code>has_key()<\/code>\u00a0(\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u0443 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0443\u0436\u0435 \u043d\u0435\u0442). \u0412\u043c\u0435\u0441\u0442\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u044f\u00a0<code>+=<\/code>\u00a0(\u043e\u043d \u0431\u044b\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0432 Python 2.0) \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u00a0<code>+<\/code>. \u041d\u0443 \u0438 \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u044f\u0437\u044b\u043a\u0430\u00a0<code>print<\/code>\u00a0\u2014 \u044d\u0442\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440, \u0430 \u043d\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043a\u0440\u0443\u0433\u043b\u044b\u0435 \u0441\u043a\u043e\u0431\u043a\u0438 \u0432\u043e\u043a\u0440\u0443\u0433\u00a0<code>letter_counts<\/code>.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u043a\u043e\u0434 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0434\u0435\u043e\u043b\u043e\u0433\u0438\u0438 LBYL-\u043f\u043e\u0434\u0445\u043e\u0434\u0430 (Look Before You Leap) \u2014 &#171;<strong>\u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438 \u043f\u0435\u0440\u0435\u0434 \u043f\u0440\u044b\u0436\u043a\u043e\u043c<\/strong>&#171;: \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435, \u0430 \u0443\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u0435\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f.<\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u0443\u044e \u0432\u044b\u0448\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438\u00a0<code>try-except<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u0436\u0435 \u0438\u043c\u0435\u043b\u0430\u0441\u044c \u0432 Python 1.4.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">letters = ['a', 'b', 'c', 'a', 'c', 'a', 't', 'p', 'b', 'a', 'y', 't', 'c'] letter_counts = {}  for char in letters:     try:         letter_counts[char] = letter_counts[char] + 1     except KeyError:         letter_counts[char] = 1  print letter_counts<\/code><\/pre>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u0442 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f):<\/p>\n<pre><code class=\"markdown\">{'a': 4, 'b': 2, 'c': 3, 't': 2, 'p': 1, 'y': 1}<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448 \u043a\u043e\u0434 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0441\u043f\u0438\u0441\u043a\u0430, \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044f \u044f\u0432\u043d\u043e \u0435\u0433\u043e \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435. \u0415\u0441\u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435, \u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0431\u0443\u0436\u0434\u0435\u043d\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u00a0<code>KeyError<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0437\u0430\u0442\u0435\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0447\u0435\u043d\u043e.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u043a\u043e\u0434 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0434\u0435\u043e\u043b\u043e\u0433\u0438\u0438 EAFP-\u043f\u043e\u0434\u0445\u043e\u0434\u0430 (Easier to Ask Forgiveness than Permission) \u2014 &#171;<strong>\u043f\u0440\u043e\u0449\u0435 \u043f\u0440\u043e\u0441\u0438\u0442\u044c \u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f, \u0447\u0435\u043c \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/strong>&#171;. \u041e\u043d\u0430, \u043a\u0441\u0442\u0430\u0442\u0438, \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 Pythonic. \u041d\u0430\u043f\u043e\u043c\u043d\u0438\u043c,\u00a0<strong>Pythonic<\/strong>\u00a0\u2014 \u0441\u0442\u0438\u043b\u044c \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0438\u0434\u0438\u043e\u043c\u0430\u043c Python, \u043e\u043d \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u0439 \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0439.<\/p>\n<h3>Python 1.5<\/h3>\n<p>\u0412 Python 1.5 \u0441\u043b\u043e\u0432\u0430\u0440\u044f\u043c \u0431\u044b\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043c\u0435\u0442\u043e\u0434\u00a0<code>get(key, default=None)<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u0432\u0430\u0440\u044f, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u043a\u043b\u044e\u0447\u0443\u00a0<code>key<\/code>, \u0435\u0441\u043b\u0438 \u043a\u043b\u044e\u0447 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435. \u0415\u0441\u043b\u0438 \u043a\u043b\u044e\u0447 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442, \u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<code>default<\/code>.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">letters = ['a', 'b', 'c', 'a', 'c', 'a', 't', 'p', 'b', 'a', 'y', 't', 'c'] letter_counts = {}  for char in letters:     letter_counts[char] = letter_counts.get(char, 0) + 1  print letter_counts<\/code><\/pre>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u0442 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f):<\/p>\n<pre><code class=\"markdown\">{'a': 4, 'b': 2, 'c': 3, 't': 2, 'p': 1, 'y': 1}<\/code><\/pre>\n<p>\u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c \u0432\u044b\u0448\u0435 \u043a\u043e\u0434\u0435 \u043c\u044b \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a\u00a0<code>letters<\/code>\u00a0\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430\u00a0<code>get()<\/code>\u00a0\u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0437 \u0441\u043b\u043e\u0432\u0430\u0440\u044f\u00a0<code>letter_counts<\/code>\u00a0\u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0441\u043f\u0438\u0441\u043a\u0430, \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0415\u0441\u043b\u0438 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 \u0435\u0449\u0435 \u043d\u0435\u0442 \u043a\u043b\u044e\u0447\u0430 \u0434\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0440\u0430\u0432\u043d\u043e\u0435\u00a0<code>0<\/code>.<\/p>\n<h3>Python 2.0<\/h3>\n<p>\u0412 Python 2.0 \u0441\u043b\u043e\u0432\u0430\u0440\u044f\u043c \u0431\u044b\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043c\u0435\u0442\u043e\u0434\u00a0<code>setdefault(key, default=None)<\/code>. \u0414\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u0432\u0430\u0440\u044f, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u043a\u043b\u044e\u0447\u0443\u00a0<code>key<\/code>, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c:<\/p>\n<ul>\n<li>\n<p>\u0435\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u044e\u0447\u00a0<code>key<\/code>\u00a0\u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435, \u043c\u0435\u0442\u043e\u0434 \u0432\u0441\u0442\u0430\u0432\u0438\u0442 \u0435\u0433\u043e \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c\u00a0<code>default<\/code>\u00a0\u0438 \u0432\u0435\u0440\u043d\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u00a0<code>default<\/code><\/p>\n<\/li>\n<li>\n<p>\u0435\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e\u00a0<code>default<\/code>\u00a0\u043d\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e \u0438 \u043a\u043b\u044e\u0447 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442, \u043c\u0435\u0442\u043e\u0434 \u0432\u0441\u0442\u0430\u0432\u0438\u0442 \u043a\u043b\u044e\u0447 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c\u00a0<code>None<\/code>\u00a0\u0438 \u0432\u0435\u0440\u043d\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u00a0<code>None<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u0412 Python 2.0 \u0442\u0430\u043a\u0436\u0435 \u0441\u0442\u0430\u043b \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u044f\u00a0<code>+=<\/code>. \u041f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043d\u0430\u0448 \u043a\u043e\u0434, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043d\u043e\u0432\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">letters = ['a', 'b', 'c', 'a', 'c', 'a', 't', 'p', 'b', 'a', 'y', 't', 'c'] letter_counts = {}  for char in letters:     letter_counts.setdefault(char, 0)     letter_counts[char] += 1  print letter_counts<\/code><\/pre>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u0442 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f):<\/p>\n<pre><code class=\"markdown\">{'a': 4, 'b': 2, 'c': 3, 't': 2, 'p': 1, 'y': 1}<\/code><\/pre>\n<p>\u041a \u043c\u0438\u043d\u0443\u0441\u0430\u043c \u0442\u0430\u043a\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043d\u0435\u0441\u0442\u0438 \u0442\u043e\u0442 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434\u00a0<code>setdefault()<\/code>\u00a0\u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e, \u043d\u0443\u0436\u0435\u043d \u043e\u043d \u0438\u043b\u0438 \u043d\u0435\u0442.<\/p>\n<h3>Python 2.3<\/h3>\n<p>\u0412 Python 2.3 \u0441\u043b\u043e\u0432\u0430\u0440\u044f\u043c \u0431\u044b\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043c\u0435\u0442\u043e\u0434\u00a0<code>fromkeys(iterable, value=None)<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0441 \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u0438\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438\u00a0<code>iterable<\/code>\u00a0\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0432\u00a0<code>value<\/code>.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">letters = ['a', 'b', 'c', 'a', 'c', 'a', 't', 'p', 'b', 'a', 'y', 't', 'c'] letter_counts = dict.fromkeys(letters, 0)  for char in letters:     letter_counts[char] += 1  print letter_counts<\/code><\/pre>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u0442 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f):<\/p>\n<pre><code class=\"markdown\">{'a': 4, 'b': 2, 'c': 3, 't': 2, 'p': 1, 'y': 1}<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043a\u043b\u044e\u0447\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0438\u0442\u044c\u0441\u044f \u043e\u0431 \u0438\u0445 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438, \u0438\u0437\u0431\u0435\u0433\u0430\u044f \u043b\u0438\u0448\u043d\u0438\u0445 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a, \u0447\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u043c \u043f\u043b\u044e\u0441\u043e\u043c.<\/p>\n<h3>Python 2.5<\/h3>\n<p>\u0421 \u0432\u044b\u0445\u043e\u0434\u043e\u043c Python 2.5 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u044f\u0437\u044b\u043a\u0430 \u0431\u044b\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043a\u043b\u0430\u0441\u0441\u00a0<code>defaultdict<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0438\u0437 \u043c\u043e\u0434\u0443\u043b\u044f\u00a0<code>collections<\/code>. \u042d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0437\u0430 \u0442\u0435\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c, \u0447\u0442\u043e \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0435\u0439 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0445 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">from collections import defaultdict  letters = ['a', 'b', 'c', 'a', 'c', 'a', 't', 'p', 'b', 'a', 'y', 't', 'c'] letter_counts = defaultdict(int)  for char in letters:     letter_counts[char] += 1  print letter_counts<\/code><\/pre>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u0442 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f):<\/p>\n<pre><code class=\"markdown\">defaultdict(&lt;class 'int'>, {'a': 4, 'b': 2, 'c': 3, 't': 2, 'p': 1, 'y': 1})<\/code><\/pre>\n<p>\u0412 \u043d\u0430\u0448\u0435\u043c \u043a\u043e\u0434\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441\u00a0<code>int<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u00a0<code>0<\/code>\u00a0\u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043a\u043b\u044e\u0447\u0435\u0439 \u0441\u043b\u043e\u0432\u0430\u0440\u044f.<\/p>\n<h3>Python 2.7<\/h3>\n<p>\u0421 \u0432\u044b\u0445\u043e\u0434\u043e\u043c Python 2.7 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u044f\u0437\u044b\u043a\u0430 \u0431\u044b\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043a\u043b\u0430\u0441\u0441\u00a0<code>Counter<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438\u00a0<code>defaultdict<\/code>, \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0438\u0437 \u043c\u043e\u0434\u0443\u043b\u044f\u00a0<code>collections<\/code>. \u041a\u043b\u0430\u0441\u0441\u00a0<code>Counter<\/code>\u00a0\u2014 \u044d\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0438\u0434 \u0441\u043b\u043e\u0432\u0430\u0440\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0442\u043e\u0447\u0435\u043d \u043f\u043e\u0434 \u043f\u043e\u0434\u0441\u0447\u0435\u0442.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">from collections import Counter  letters = ['a', 'b', 'c', 'a', 'c', 'a', 't', 'p', 'b', 'a', 'y', 't', 'c'] letter_counts = Counter(letters)  print letter_counts<\/code><\/pre>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u0442 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f):<\/p>\n<pre><code class=\"markdown\">Counter({'a': 4, 'c': 3, 'b': 2, 't': 2, 'p': 1, 'y': 1})<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430\u00a0<code>Counter<\/code>\u00a0\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f, \u043f\u043e\u0436\u0430\u043b\u0443\u0439, \u0441\u0430\u043c\u044b\u043c Pythonic \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c: \u043f\u0440\u043e\u0449\u0435 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u0443\u0436\u0435 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0434\u0430 \u0438 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e!<\/p>\n<p>\u041e\u0442\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u043a\u043b\u0430\u0441\u0441\u044b\u00a0<code>defaultdict<\/code>\u00a0\u0438\u00a0<code>Counter<\/code>\u00a0\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439, \u0442\u043e \u0435\u0441\u0442\u044c \u0442\u0438\u043f\u0430\u00a0<code>dict<\/code>.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">from collections import defaultdict, Counter  print(issubclass(defaultdict, dict)) print(issubclass(Counter, dict))<\/code><\/pre>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u0442:<\/p>\n<pre><code class=\"markdown\">True True<\/code><\/pre>\n<h3>Python 3.x<\/h3>\n<p>\u0412 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c Python (\u0432\u0435\u0440\u0441\u0438\u044f 3.x) \u0441\u0430\u043c\u044b\u043c Pythonic \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0440\u0435\u0448\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u043a\u043b\u0430\u0441\u0441\u00a0<code>Counter<\/code>.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">from collections import Counter  letters = ['a', 'b', 'c', 'a', 'c', 'a', 't', 'p', 'b', 'a', 'y', 't', 'c'] letter_counts = Counter(letters)  print(letter_counts)<\/code><\/pre>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u0442:<\/p>\n<pre><code class=\"markdown\">Counter({'a': 4, 'c': 3, 'b': 2, 't': 2, 'p': 1, 'y': 1})<\/code><\/pre>\n<p>\u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u044f\u0437\u044b\u043a\u0430 \u043a\u043b\u0430\u0441\u0441\u00a0<code>Counter<\/code>\u00a0\u0441\u0442\u0430\u043b \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0435\u0433\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0434 \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430. \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430\u00a0<code>Counter<\/code>\u00a0\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043f\u043e\u00a0<a href=\"https:\/\/github.com\/python\/cpython\/blob\/8d999cbf4adea053be6dbb612b9844635c4dfb8e\/Lib\/collections\/__init__.py#L466\" rel=\"noopener noreferrer nofollow\">\u0441\u0441\u044b\u043b\u043a\u0435<\/a>.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0438\u0438 Python &#171;\u0434\u043e\u043b\u0436\u0435\u043d \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0438 \u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e&#187;. \u041d\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0435 \u0431\u044b\u0432\u0430\u0435\u0442 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c, \u0430 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u2014\u00a0\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u043c. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043c\u043e\u0436\u0435\u0442 \u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u044f\u0437\u044b\u043a\u0430 \u0438 \u043d\u0430\u0448\u0438\u0445 \u0437\u043d\u0430\u043d\u0438\u0439.<\/p>\n<p>P.S. \u0421\u043b\u043e\u0432\u0430\u0440\u0438 \u0432 Python \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442 \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043e\u043d\u0438 \u043e\u0447\u0435\u043d\u044c \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0441\u0430\u043c\u0438\u043c \u044f\u0437\u044b\u043a\u043e\u043c &#171;\u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c&#187;. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u0438\u0445 \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b, \u043f\u0438\u0448\u0443\u0449\u0438\u0435 \u043d\u0430 Python. \u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u044f\u0437\u044b\u043a\u0430 \u0441\u043b\u043e\u0432\u0430\u0440\u0438 \u0441\u0438\u043b\u044c\u043d\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438: \u043e\u043d\u0438 \u0441\u0442\u0430\u043b\u0438 \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u044e\u0442 \u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u0430\u043c\u044f\u0442\u0438, \u0430 \u0435\u0449\u0435 \u0441\u0442\u0430\u043b\u0438 \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u044b\u043c\u0438.<\/p>\n<p>\u041f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0439\u0442\u0435\u0441\u044c \u043a \u043d\u0430\u0448\u0435\u043c\u0443\u00a0<a href=\"https:\/\/t.me\/pygen_ru\" rel=\"noopener noreferrer nofollow\">\u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c-\u043a\u0430\u043d\u0430\u043b\u0443<\/a>, \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0438 \u043f\u043e\u0437\u043d\u0430\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e! <\/p>\n<p>\u2764\ufe0fHappy Pythoning!?<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/817529\/\"> https:\/\/habr.com\/ru\/articles\/817529\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0423 \u043e\u0434\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u044f. \u0412\u043e\u0437\u044c\u043c\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u2014\u00a0<strong>\u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430<\/strong>,<strong>\u00a0<\/strong>\u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0441\u0447\u0438\u0442\u0430\u0435\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441\u043f\u0438\u0441\u043a\u0430 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0435\u043c. \u0421\u043f\u043e\u0441\u043e\u0431 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430 Python \u043c\u0435\u043d\u044f\u043b\u0441\u044f \u043f\u043e \u043c\u0435\u0440\u0435 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044f \u044f\u0437\u044b\u043a\u0430. \u0418\u043c\u0435\u043d\u043d\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.<\/p>\n<p>\u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0438\u0437 \u043d\u0430\u0441 \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u043b\u043e\u0441\u044c \u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u043d\u0430 Python \u0441 \u0435\u0433\u043e \u0442\u0440\u0435\u0442\u044c\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438. \u041e\u0434\u043d\u0430\u043a\u043e \u043c\u044b \u043d\u0430\u0447\u043d\u0435\u043c \u0441 Python 1.4. \u041f\u0440\u0438\u0441\u0442\u0435\u0433\u043d\u0438\u0442\u0435 \u0440\u0435\u043c\u043d\u0438, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u0441\u044f \u0432 \u0434\u0430\u043b\u0435\u043a\u043e\u0435 \u043f\u0440\u043e\u0448\u043b\u043e\u0435 \u2014 \u0432 1997 \u0433\u043e\u0434!<\/p>\n<figure class=\"full-width\"><\/figure>\n<h4>Python 1.4<\/h4>\n<p>\u041c\u0430\u043b\u043e \u043a\u0442\u043e \u043f\u043e\u043c\u043d\u0438\u0442 \u044d\u0442\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0430. \u042d\u0442\u043e \u0434\u0430\u0436\u0435 \u043d\u0435 Python 2. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0443\u0436\u0435 \u0432 \u044d\u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u044f\u0437\u044b\u043a\u0430 \u0431\u044b\u043b\u0438 \u0441\u043b\u043e\u0432\u0430\u0440\u0438 \u2014 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445\u00a0<code>dict<\/code>.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">letters = ['a', 'b', 'c', 'a', 'c', 'a', 't', 'p', 'b', 'a', 'y', 't', 'c'] letter_counts = {}  for char in letters:     if letter_counts.has_key(char):         letter_counts[char] = letter_counts[char] + 1     else:         letter_counts[char] = 1          print letter_counts<\/code><\/pre>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u0442 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f):<\/p>\n<pre><code class=\"markdown\">{'a': 4, 'b': 2, 'c': 3, 't': 2, 'p': 1, 'y': 1}<\/code><\/pre>\n<p>\u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c \u0432\u044b\u0448\u0435 \u043a\u043e\u0434\u0435 \u043c\u044b \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a\u00a0<code>letters<\/code>\u00a0\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043d\u0430 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0435\u0433\u043e \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u00a0<code>letter_counts<\/code>. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u043c\u044b \u0435\u0433\u043e \u0442\u0443\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c, \u0430 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u0435\u0433\u043e \u0441\u0447\u0435\u0442\u0447\u0438\u043a.<\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0432 Python 1.4 \u0432\u043c\u0435\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e\u0433\u043e \u043d\u0430\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u0438\u00a0<code>in<\/code>\u00a0(\u043e\u043d \u0431\u044b\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0432 Python 2.2) \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434\u00a0<code>has_key()<\/code>\u00a0(\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u0443 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0443\u0436\u0435 \u043d\u0435\u0442). \u0412\u043c\u0435\u0441\u0442\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u044f\u00a0<code>+=<\/code>\u00a0(\u043e\u043d \u0431\u044b\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0432 Python 2.0) \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u00a0<code>+<\/code>. \u041d\u0443 \u0438 \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u044f\u0437\u044b\u043a\u0430\u00a0<code>print<\/code>\u00a0\u2014 \u044d\u0442\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440, \u0430 \u043d\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043a\u0440\u0443\u0433\u043b\u044b\u0435 \u0441\u043a\u043e\u0431\u043a\u0438 \u0432\u043e\u043a\u0440\u0443\u0433\u00a0<code>letter_counts<\/code>.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u043a\u043e\u0434 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0434\u0435\u043e\u043b\u043e\u0433\u0438\u0438 LBYL-\u043f\u043e\u0434\u0445\u043e\u0434\u0430 (Look Before You Leap) \u2014 &#171;<strong>\u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438 \u043f\u0435\u0440\u0435\u0434 \u043f\u0440\u044b\u0436\u043a\u043e\u043c<\/strong>&#171;: \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435, \u0430 \u0443\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u0435\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f.<\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u0443\u044e \u0432\u044b\u0448\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438\u00a0<code>try-except<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u0436\u0435 \u0438\u043c\u0435\u043b\u0430\u0441\u044c \u0432 Python 1.4.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">letters = ['a', 'b', 'c', 'a', 'c', 'a', 't', 'p', 'b', 'a', 'y', 't', 'c'] letter_counts = {}  for char in letters:     try:         letter_counts[char] = letter_counts[char] + 1     except KeyError:         letter_counts[char] = 1  print letter_counts<\/code><\/pre>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u0442 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f):<\/p>\n<pre><code class=\"markdown\">{'a': 4, 'b': 2, 'c': 3, 't': 2, 'p': 1, 'y': 1}<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448 \u043a\u043e\u0434 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0441\u043f\u0438\u0441\u043a\u0430, \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044f \u044f\u0432\u043d\u043e \u0435\u0433\u043e \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435. \u0415\u0441\u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435, \u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0431\u0443\u0436\u0434\u0435\u043d\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u00a0<code>KeyError<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0437\u0430\u0442\u0435\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0447\u0435\u043d\u043e.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u043a\u043e\u0434 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0434\u0435\u043e\u043b\u043e\u0433\u0438\u0438 EAFP-\u043f\u043e\u0434\u0445\u043e\u0434\u0430 (Easier to Ask Forgiveness than Permission) \u2014 &#171;<strong>\u043f\u0440\u043e\u0449\u0435 \u043f\u0440\u043e\u0441\u0438\u0442\u044c \u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f, \u0447\u0435\u043c \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/strong>&#171;. \u041e\u043d\u0430, \u043a\u0441\u0442\u0430\u0442\u0438, \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 Pythonic. \u041d\u0430\u043f\u043e\u043c\u043d\u0438\u043c,\u00a0<strong>Pythonic<\/strong>\u00a0\u2014 \u0441\u0442\u0438\u043b\u044c \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0438\u0434\u0438\u043e\u043c\u0430\u043c Python, \u043e\u043d \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u0439 \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0439.<\/p>\n<h3>Python 1.5<\/h3>\n<p>\u0412 Python 1.5 \u0441\u043b\u043e\u0432\u0430\u0440\u044f\u043c \u0431\u044b\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043c\u0435\u0442\u043e\u0434\u00a0<code>get(key, default=None)<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u0432\u0430\u0440\u044f, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u043a\u043b\u044e\u0447\u0443\u00a0<code>key<\/code>, \u0435\u0441\u043b\u0438 \u043a\u043b\u044e\u0447 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435. \u0415\u0441\u043b\u0438 \u043a\u043b\u044e\u0447 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442, \u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<code>default<\/code>.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">letters = ['a', 'b', 'c', 'a', 'c', 'a', 't', 'p', 'b', 'a', 'y', 't', 'c'] letter_counts = {}  for char in letters:     letter_counts[char] = letter_counts.get(char, 0) + 1  print letter_counts<\/code><\/pre>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u0442 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f):<\/p>\n<pre><code class=\"markdown\">{'a': 4, 'b': 2, 'c': 3, 't': 2, 'p': 1, 'y': 1}<\/code><\/pre>\n<p>\u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c \u0432\u044b\u0448\u0435 \u043a\u043e\u0434\u0435 \u043c\u044b \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a\u00a0<code>letters<\/code>\u00a0\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430\u00a0<code>get()<\/code>\u00a0\u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0437 \u0441\u043b\u043e\u0432\u0430\u0440\u044f\u00a0<code>letter_counts<\/code>\u00a0\u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0441\u043f\u0438\u0441\u043a\u0430, \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0415\u0441\u043b\u0438 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 \u0435\u0449\u0435 \u043d\u0435\u0442 \u043a\u043b\u044e\u0447\u0430 \u0434\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0440\u0430\u0432\u043d\u043e\u0435\u00a0<code>0<\/code>.<\/p>\n<h3>Python 2.0<\/h3>\n<p>\u0412 Python 2.0 \u0441\u043b\u043e\u0432\u0430\u0440\u044f\u043c \u0431\u044b\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043c\u0435\u0442\u043e\u0434\u00a0<code>setdefault(key, default=None)<\/code>. \u0414\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u0432\u0430\u0440\u044f, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u043a\u043b\u044e\u0447\u0443\u00a0<code>key<\/code>, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c:<\/p>\n<ul>\n<li>\n<p>\u0435\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u044e\u0447\u00a0<code>key<\/code>\u00a0\u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435, \u043c\u0435\u0442\u043e\u0434 \u0432\u0441\u0442\u0430\u0432\u0438\u0442 \u0435\u0433\u043e \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c\u00a0<code>default<\/code>\u00a0\u0438 \u0432\u0435\u0440\u043d\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u00a0<code>default<\/code><\/p>\n<\/li>\n<li>\n<p>\u0435\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e\u00a0<code>default<\/code>\u00a0\u043d\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e \u0438 \u043a\u043b\u044e\u0447 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442, \u043c\u0435\u0442\u043e\u0434 \u0432\u0441\u0442\u0430\u0432\u0438\u0442 \u043a\u043b\u044e\u0447 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c\u00a0<code>None<\/code>\u00a0\u0438 \u0432\u0435\u0440\u043d\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u00a0<code>None<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u0412 Python 2.0 \u0442\u0430\u043a\u0436\u0435 \u0441\u0442\u0430\u043b \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u044f\u00a0<code>+=<\/code>. \u041f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043d\u0430\u0448 \u043a\u043e\u0434, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043d\u043e\u0432\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">letters = ['a', 'b', 'c', 'a', 'c', 'a', 't', 'p', 'b', 'a', 'y', 't', 'c'] letter_counts = {}  for char in letters:     letter_counts.setdefault(char, 0)     letter_counts[char] += 1  print letter_counts<\/code><\/pre>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u0442 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f):<\/p>\n<pre><code class=\"markdown\">{'a': 4, 'b': 2, 'c': 3, 't': 2, 'p': 1, 'y': 1}<\/code><\/pre>\n<p>\u041a \u043c\u0438\u043d\u0443\u0441\u0430\u043c \u0442\u0430\u043a\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043d\u0435\u0441\u0442\u0438 \u0442\u043e\u0442 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434\u00a0<code>setdefault()<\/code>\u00a0\u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e, \u043d\u0443\u0436\u0435\u043d \u043e\u043d \u0438\u043b\u0438 \u043d\u0435\u0442.<\/p>\n<h3>Python 2.3<\/h3>\n<p>\u0412 Python 2.3 \u0441\u043b\u043e\u0432\u0430\u0440\u044f\u043c \u0431\u044b\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043c\u0435\u0442\u043e\u0434\u00a0<code>fromkeys(iterable, value=None)<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0441 \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u0438\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438\u00a0<code>iterable<\/code>\u00a0\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0432\u00a0<code>value<\/code>.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">letters = ['a', 'b', 'c', 'a', 'c', 'a', 't', 'p', 'b', 'a', 'y', 't', 'c'] letter_counts = dict.fromkeys(letters, 0)  for char in letters:     letter_counts[char] += 1  print letter_counts<\/code><\/pre>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u0442 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f):<\/p>\n<pre><code class=\"markdown\">{'a': 4, 'b': 2, 'c': 3, 't': 2, 'p': 1, 'y': 1}<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043a\u043b\u044e\u0447\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0438\u0442\u044c\u0441\u044f \u043e\u0431 \u0438\u0445 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438, \u0438\u0437\u0431\u0435\u0433\u0430\u044f \u043b\u0438\u0448\u043d\u0438\u0445 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a, \u0447\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u043c \u043f\u043b\u044e\u0441\u043e\u043c.<\/p>\n<h3>Python 2.5<\/h3>\n<p>\u0421 \u0432\u044b\u0445\u043e\u0434\u043e\u043c Python 2.5 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u044f\u0437\u044b\u043a\u0430 \u0431\u044b\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043a\u043b\u0430\u0441\u0441\u00a0<code>defaultdict<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0438\u0437 \u043c\u043e\u0434\u0443\u043b\u044f\u00a0<code>collections<\/code>. \u042d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0437\u0430 \u0442\u0435\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c, \u0447\u0442\u043e \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0435\u0439 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0445 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">from collections import defaultdict  letters = ['a', 'b', 'c', 'a', 'c', 'a', 't', 'p', 'b', 'a', 'y', 't', 'c'] letter_counts = defaultdict(int)  for char in letters:     letter_counts[char] += 1  print letter_counts<\/code><\/pre>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u0442 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f):<\/p>\n<pre><code class=\"markdown\">defaultdict(&lt;class 'int'>, {'a': 4, 'b': 2, 'c': 3, 't': 2, 'p': 1, 'y': 1})<\/code><\/pre>\n<p>\u0412 \u043d\u0430\u0448\u0435\u043c \u043a\u043e\u0434\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441\u00a0<code>int<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u00a0<code>0<\/code>\u00a0\u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043a\u043b\u044e\u0447\u0435\u0439 \u0441\u043b\u043e\u0432\u0430\u0440\u044f.<\/p>\n<h3>Python 2.7<\/h3>\n<p>\u0421 \u0432\u044b\u0445\u043e\u0434\u043e\u043c Python 2.7 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u044f\u0437\u044b\u043a\u0430 \u0431\u044b\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043a\u043b\u0430\u0441\u0441\u00a0<code>Counter<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438\u00a0<code>defaultdict<\/code>, \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0438\u0437 \u043c\u043e\u0434\u0443\u043b\u044f\u00a0<code>collections<\/code>. \u041a\u043b\u0430\u0441\u0441\u00a0<code>Counter<\/code>\u00a0\u2014 \u044d\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0438\u0434 \u0441\u043b\u043e\u0432\u0430\u0440\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0442\u043e\u0447\u0435\u043d \u043f\u043e\u0434 \u043f\u043e\u0434\u0441\u0447\u0435\u0442.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">from collections import Counter  letters = ['a', 'b', 'c', 'a', 'c', 'a', 't', 'p', 'b', 'a', 'y', 't', 'c'] letter_counts = Counter(letters)  print letter_counts<\/code><\/pre>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u0442 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f):<\/p>\n<pre><code class=\"markdown\">Counter({'a': 4, 'c': 3, 'b': 2, 't': 2, 'p': 1, 'y': 1})<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430\u00a0<code>Counter<\/code>\u00a0\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f, \u043f\u043e\u0436\u0430\u043b\u0443\u0439, \u0441\u0430\u043c\u044b\u043c Pythonic \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c: \u043f\u0440\u043e\u0449\u0435 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u0443\u0436\u0435 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0434\u0430 \u0438 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e!<\/p>\n<p>\u041e\u0442\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u043a\u043b\u0430\u0441\u0441\u044b\u00a0<code>defaultdict<\/code>\u00a0\u0438\u00a0<code>Counter<\/code>\u00a0\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439, \u0442\u043e \u0435\u0441\u0442\u044c \u0442\u0438\u043f\u0430\u00a0<code>dict<\/code>.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">from collections import defaultdict, Counter  print(issubclass(defaultdict, dict)) print(issubclass(Counter, dict))<\/code><\/pre>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u0442:<\/p>\n<pre><code class=\"markdown\">True True<\/code><\/pre>\n<h3>Python 3.x<\/h3>\n<p>\u0412 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c Python (\u0432\u0435\u0440\u0441\u0438\u044f 3.x) \u0441\u0430\u043c\u044b\u043c Pythonic \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0440\u0435\u0448\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u043a\u043b\u0430\u0441\u0441\u00a0<code>Counter<\/code>.<\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">from collections import Counter  letters = ['a', 'b', 'c', 'a', 'c', 'a', 't', 'p', 'b', 'a', 'y', 't', 'c'] letter_counts = Counter(letters)  print(letter_counts)<\/code><\/pre>\n<p>\u0432\u044b\u0432\u043e\u0434\u0438\u0442:<\/p>\n<pre><code class=\"markdown\">Counter({'a': 4, 'c': 3, 'b': 2, 't': 2, 'p': 1, 'y': 1})<\/code><\/pre>\n<p>\u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u044f\u0437\u044b\u043a\u0430 \u043a\u043b\u0430\u0441\u0441\u00a0<code>Counter<\/code>\u00a0\u0441\u0442\u0430\u043b \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0435\u0433\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0434 \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430. \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430\u00a0<code>Counter<\/code>\u00a0\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043f\u043e\u00a0<a href=\"https:\/\/github.com\/python\/cpython\/blob\/8d999cbf4adea053be6dbb612b9844635c4dfb8e\/Lib\/collections\/__init__.py#L466\" rel=\"noopener noreferrer nofollow\">\u0441\u0441\u044b\u043b\u043a\u0435<\/a>.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0438\u0438 Python &#171;\u0434\u043e\u043b\u0436\u0435\u043d \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0438 \u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e&#187;. \u041d\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0435 \u0431\u044b\u0432\u0430\u0435\u0442 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c, \u0430 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u2014\u00a0\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u043c. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043c\u043e\u0436\u0435\u0442 \u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u044f\u0437\u044b\u043a\u0430 \u0438 \u043d\u0430\u0448\u0438\u0445 \u0437\u043d\u0430\u043d\u0438\u0439.<\/p>\n<p>P.S. \u0421\u043b\u043e\u0432\u0430\u0440\u0438 \u0432 Python \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442 \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043e\u043d\u0438 \u043e\u0447\u0435\u043d\u044c \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0441\u0430\u043c\u0438\u043c \u044f\u0437\u044b\u043a\u043e\u043c &#171;\u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c&#187;. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u0438\u0445 \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b, \u043f\u0438\u0448\u0443\u0449\u0438\u0435 \u043d\u0430 Python. \u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u044f\u0437\u044b\u043a\u0430 \u0441\u043b\u043e\u0432\u0430\u0440\u0438 \u0441\u0438\u043b\u044c\u043d\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438: \u043e\u043d\u0438 \u0441\u0442\u0430\u043b\u0438 \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u044e\u0442 \u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u0430\u043c\u044f\u0442\u0438, \u0430 \u0435\u0449\u0435 \u0441\u0442\u0430\u043b\u0438 \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u044b\u043c\u0438.<\/p>\n<p>\u041f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0439\u0442\u0435\u0441\u044c \u043a \u043d\u0430\u0448\u0435\u043c\u0443\u00a0<a href=\"https:\/\/t.me\/pygen_ru\" rel=\"noopener noreferrer nofollow\">\u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c-\u043a\u0430\u043d\u0430\u043b\u0443<\/a>, \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0438 \u043f\u043e\u0437\u043d\u0430\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e! <\/p>\n<p>\u2764\ufe0fHappy Pythoning!?<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/817529\/\"> https:\/\/habr.com\/ru\/articles\/817529\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-377705","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/377705","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=377705"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/377705\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=377705"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=377705"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=377705"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}