{"id":257156,"date":"2015-05-14T03:26:02","date_gmt":"2015-05-13T23:26:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=257156"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=257156","title":{"rendered":"\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 Python"},"content":{"rendered":"<p>       \u0420\u0430\u0441\u0441\u0443\u0436\u0434\u0430\u044f \u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438, \u043b\u044e\u0434\u0438 \u0447\u0430\u0441\u0442\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u0443\u0447\u0443 \u00ab\u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445\u00bb \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a. \u041d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0445\u0432\u043e\u0441\u0442\u043e\u0432\u043e\u0439 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438. \u042d\u0442\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u044f\u0437\u044b\u043a\u0430, \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0449\u0438\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u041e\u043d\u0438 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u044e\u0442 \u043c\u0430\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432\u044b\u0441\u0448\u0435\u0433\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0430. \u042d\u0442\u043e \u043f\u0440\u0438\u0451\u043c\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0435\u0441\u044f \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u041e\u043d\u0438 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u044e\u0442 \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u043d\u0438\u0435, \u043b\u0435\u043d\u0438\u0432\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0438 \u0434\u0435\u0442\u0435\u0440\u043c\u0435\u043d\u0438\u0437\u043c. \u042d\u0442\u043e \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c.<\/p>\n<p>  \u0417\u0430\u0431\u0435\u0439\u0442\u0435. \u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u0438\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e\u043c: \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435\u043c \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0445 \u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432. \u041e\u043d \u043d\u0435 \u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u043d\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0438 \u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0435\u0441\u044f \u0432\u043d\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0412\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u00ab\u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u00bb \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0438\u0437 \u044d\u0442\u043e\u0433\u043e. <\/p>\n<p>  \u041d\u0435\u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f:<\/p>\n<pre><code class=\"python\">a = 0 def increment1():     global a     a += 1 <\/code><\/pre>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f:<\/p>\n<pre><code class=\"python\">def increment2(a):     return a + 1 <\/code><\/pre>\n<p>  \u0412\u043c\u0435\u0441\u0442\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u043e\u0432 \u043f\u043e \u0441\u043f\u0438\u0441\u043a\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 map \u0438 reduce<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>Map<\/h4>\n<p>  \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445. \u0421\u043e\u0437\u0434\u0430\u0451\u0442 \u043d\u043e\u0432\u0443\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043d\u043e\u0432\u0443\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e. \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u043e\u0432\u0443\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e.<\/p>\n<p>  \u041f\u0440\u043e\u0441\u0442\u043e\u0439 map, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u043c\u0451\u043d \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0434\u043b\u0438\u043d:<\/p>\n<pre><code class=\"python\">name_lengths = map(len, ['\u041c\u0430\u0448\u0430', '\u041f\u0435\u0442\u044f', '\u0412\u0430\u0441\u044f'])  print name_lengths # =&gt; [4, 4, 3] <\/code><\/pre>\n<p>  \u042d\u0442\u043e\u0442 map \u0432\u043e\u0437\u0432\u043e\u0434\u0438\u0442 \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442:<\/p>\n<pre><code class=\"python\">squares = map(lambda x: x * x, [0, 1, 2, 3, 4])  print squares # =&gt; [0, 1, 4, 9, 16] <\/code><\/pre>\n<p>  \u041e\u043d \u043d\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0430 \u0431\u0435\u0440\u0451\u0442 \u0430\u043d\u043e\u043d\u0438\u043c\u043d\u0443\u044e, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u0443\u044e \u0447\u0435\u0440\u0435\u0437 lambda. \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b lambda \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0441\u043b\u0435\u0432\u0430 \u043e\u0442 \u0434\u0432\u043e\u0435\u0442\u043e\u0447\u0438\u044f. \u0422\u0435\u043b\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u2013 \u0441\u043f\u0440\u0430\u0432\u0430. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u044f\u0432\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<p>  \u041d\u0435\u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u043c\u0451\u043d \u0438 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0437\u0432\u0438\u0449\u0430\u043c\u0438.<\/p>\n<pre><code class=\"python\">import random  names = ['\u041c\u0430\u0448\u0430', '\u041f\u0435\u0442\u044f', '\u0412\u0430\u0441\u044f'] code_names = ['\u0428\u043f\u0443\u043d\u0442\u0438\u043a', '\u0412\u0438\u043d\u0442\u0438\u043a', '\u0424\u0443\u043d\u0442\u0438\u043a']  for i in range(len(names)):     names[i] = random.choice(code_names)  print names # =&gt; ['\u0428\u043f\u0443\u043d\u0442\u0438\u043a', '\u0412\u0438\u043d\u0442\u0438\u043a', '\u0428\u043f\u0443\u043d\u0442\u0438\u043a'] <\/code><\/pre>\n<p>  \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u043f\u0440\u043e\u0437\u0432\u0438\u0449\u0430 \u0440\u0430\u0437\u043d\u044b\u043c \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u044b\u043c \u0430\u0433\u0435\u043d\u0442\u0430\u043c. \u0411\u0443\u0434\u0435\u043c \u043d\u0430\u0434\u0435\u044f\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435 \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u0442 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u043c\u0438\u0441\u0441\u0438\u0438.<\/p>\n<p>  \u041f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u044d\u0442\u043e \u0447\u0435\u0440\u0435\u0437 map:<\/p>\n<pre><code class=\"python\">import random  names = ['\u041c\u0430\u0448\u0430', '\u041f\u0435\u0442\u044f', '\u0412\u0430\u0441\u044f']  secret_names = map(lambda x: random.choice(['\u0428\u043f\u0443\u043d\u0442\u0438\u043a', '\u0412\u0438\u043d\u0442\u0438\u043a', '\u0424\u0443\u043d\u0442\u0438\u043a']), names) <\/code><\/pre>\n<p>  <b>\u0423\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0435 1<\/b>. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 map. \u041e\u043d \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0438\u043c\u0451\u043d \u0438 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u0438\u0445 \u043f\u0440\u043e\u0437\u0432\u0438\u0449\u0430\u043c\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0431\u043e\u043b\u0435\u0435 \u043d\u0430\u0434\u0451\u0436\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434.<\/p>\n<pre><code class=\"python\">names = ['\u041c\u0430\u0448\u0430', '\u041f\u0435\u0442\u044f', '\u0412\u0430\u0441\u044f']  for i in range(len(names)):     names[i] = hash(names[i])  print names # =&gt; [6306819796133686941, 8135353348168144921, -1228887169324443034] <\/code><\/pre>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041c\u043e\u0451 \u0440\u0435\u0448\u0435\u043d\u0438\u0435:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">names = ['\u041c\u0430\u0448\u0430', '\u041f\u0435\u0442\u044f', '\u0412\u0430\u0441\u044f']  secret_names = map(hash, names) <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h4>Reduce<\/h4>\n<p>  Reduce \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u043d\u0430\u0431\u043e\u0440 \u043f\u0443\u043d\u043a\u0442\u043e\u0432. \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u043e\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0432\u0441\u0435\u0445 \u043f\u0443\u043d\u043a\u0442\u043e\u0432.<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e reduce. \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0443\u043c\u043c\u0443 \u0432\u0441\u0435\u0445 \u043f\u0443\u043d\u043a\u0442\u043e\u0432 \u0432 \u043d\u0430\u0431\u043e\u0440\u0435:<\/p>\n<pre><code class=\"python\">sum = reduce(lambda a, x: a + x, [0, 1, 2, 3, 4])  print sum # =&gt; 10 <\/code><\/pre>\n<p>  x \u2013 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043f\u0443\u043d\u043a\u0442, \u0430 \u2013 \u0430\u043a\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u043e\u0440. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 lambda \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u0443\u043d\u043a\u0442\u0435. reduce() \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u0442 \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e lambda \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u0445 \u0430 \u0438 \u0445, \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0430 \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438.<\/p>\n<p>  \u0410 \u0447\u0435\u043c\u0443 \u0440\u0430\u0432\u043d\u043e \u0430 \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438? \u041e\u043d\u043e \u0440\u0430\u0432\u043d\u043e \u043f\u0435\u0440\u0432\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438, \u0438 reduce() \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043e \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430. \u0422\u043e \u0435\u0441\u0442\u044c, \u043f\u0435\u0440\u0432\u044b\u0439 \u0445 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u0435\u043d \u0432\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u0443 \u043d\u0430\u0431\u043e\u0440\u0430.<\/p>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u0447\u0438\u0442\u0430\u0435\u0442, \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u043e \u0441\u043b\u043e\u0432\u043e \u00ab\u043a\u0430\u043f\u0438\u0442\u0430\u043d\u00bb \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u0441\u0442\u0440\u043e\u043a:<\/p>\n<pre><code class=\"python\">sentences = ['\u043a\u0430\u043f\u0438\u0442\u0430\u043d \u0434\u0436\u0435\u043a \u0432\u043e\u0440\u043e\u0431\u0435\u0439',              '\u043a\u0430\u043f\u0438\u0442\u0430\u043d \u0434\u0430\u043b\u044c\u043d\u0435\u0433\u043e \u043f\u043b\u0430\u0432\u0430\u043d\u0438\u044f',              '\u0432\u0430\u0448\u0430 \u043b\u043e\u0434\u043a\u0430 \u0433\u043e\u0442\u043e\u0432\u0430, \u043a\u0430\u043f\u0438\u0442\u0430\u043d']  cap_count = 0 for sentence in sentences:     cap_count += sentence.count('\u043a\u0430\u043f\u0438\u0442\u0430\u043d')  print cap_count # =&gt; 3 <\/code><\/pre>\n<p>  \u0422\u043e\u0442 \u0436\u0435 \u043a\u043e\u0434 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c reduce:<\/p>\n<pre><code class=\"python\">sentences = ['\u043a\u0430\u043f\u0438\u0442\u0430\u043d \u0434\u0436\u0435\u043a \u0432\u043e\u0440\u043e\u0431\u0435\u0439',              '\u043a\u0430\u043f\u0438\u0442\u0430\u043d \u0434\u0430\u043b\u044c\u043d\u0435\u0433\u043e \u043f\u043b\u0430\u0432\u0430\u043d\u0438\u044f',              '\u0432\u0430\u0448\u0430 \u043b\u043e\u0434\u043a\u0430 \u0433\u043e\u0442\u043e\u0432\u0430, \u043a\u0430\u043f\u0438\u0442\u0430\u043d']  cap_count = reduce(lambda a, x: a + x.count('\u043a\u0430\u043f\u0438\u0442\u0430\u043d'),                    sentences,                    0) <\/code><\/pre>\n<p>  \u0410 \u043e\u0442\u043a\u0443\u0434\u0430 \u0437\u0434\u0435\u0441\u044c \u0431\u0435\u0440\u0451\u0442\u0441\u044f \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0430? \u041e\u043d\u043e \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u043e \u0438\u0437 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u0439 \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d\u043e \u0437\u0430\u0434\u0430\u0451\u0442\u0441\u044f \u043a\u0430\u043a \u0442\u0440\u0435\u0442\u0438\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 reduce().<\/p>\n<h4>\u041f\u043e\u0447\u0435\u043c\u0443 map \u0438 reduce \u043b\u0443\u0447\u0448\u0435?<\/h4>\n<p>  \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043e\u043d\u0438 \u043e\u0431\u044b\u0447\u043d\u043e \u0443\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0443.<\/p>\n<p>  \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u0432\u0430\u0436\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438,\u2013 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f, \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435,\u2013 \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435 map \u0438 reduce.<\/p>\n<p>  \u0412-\u0442\u0440\u0435\u0442\u044c\u0438\u0445, \u043a\u043e\u0434 \u0432 \u0446\u0438\u043a\u043b\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u043d\u0435\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u0438\u043b\u0438 \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u043a\u043e\u0434, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0439\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u043d\u0435\u0433\u043e. \u041f\u043e \u0441\u043e\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u044e, map \u0438 reduce \u2013 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b.<\/p>\n<p>  \u0412-\u0447\u0435\u0442\u0432\u0451\u0440\u0442\u044b\u0445, map \u0438 reduce \u2013 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438. \u0412\u043c\u0435\u0441\u0442\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u043e\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u044f \u0446\u0438\u043a\u043b\u043e\u0432 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044e \u043f\u0440\u043e\u0449\u0435 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c map \u0438 reduce, \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u0432 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b.<\/p>\n<p>  \u0412-\u043f\u044f\u0442\u044b\u0445, \u0443 \u043d\u0438\u0445 \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0434\u0440\u0443\u0437\u0435\u0439, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0445 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0435, \u0441\u043b\u0435\u0433\u043a\u0430 \u0438\u0437\u043c\u0435\u043d\u0451\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u044d\u0442\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, filter, all, any \u0438 find.<\/p>\n<p>  <b>\u0423\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0435 2<\/b>: \u043f\u0435\u0440\u0435\u043f\u0438\u0448\u0438\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f map, reduce \u0438 filter. Filter \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e. \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0442\u0435\u0445 \u0432\u0435\u0449\u0435\u0439, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 True.<\/p>\n<pre><code class=\"python\">people = [{'\u0438\u043c\u044f': '\u041c\u0430\u0448\u0430', '\u0440\u043e\u0441\u0442': 160},     {' \u0440\u043e\u0441\u0442 ': '\u0421\u0430\u0448\u0430', ' \u0440\u043e\u0441\u0442 ': 80},     {'name': '\u041f\u0430\u0448\u0430'}]  height_total = 0 height_count = 0 for person in people:     if '\u0440\u043e\u0441\u0442' in person:         height_total += person[' \u0440\u043e\u0441\u0442 ']         height_count += 1  if height_count &gt; 0:     average_height = height_total \/ height_count      print average_height     # =&gt; 120 <\/code><\/pre>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041c\u043e\u0451 \u0440\u0435\u0448\u0435\u043d\u0438\u0435:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">people = [{'\u0438\u043c\u044f': '\u041c\u0430\u0448\u0430', '\u0440\u043e\u0441\u0442': 160},     {' \u0440\u043e\u0441\u0442 ': '\u0421\u0430\u0448\u0430', ' \u0440\u043e\u0441\u0442 ': 80},     {'name': '\u041f\u0430\u0448\u0430'}]  heights = map(lambda x: x['\u0440\u043e\u0441\u0442'],               filter(lambda x: '\u0440\u043e\u0441\u0442' in x, people))  if len(heights) &gt; 0:     from operator import add     average_height = reduce(add, heights) \/ len(heights) <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h4>\u041f\u0438\u0448\u0438\u0442\u0435 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e, \u0430 \u043d\u0435 \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e<\/h4>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u044d\u043c\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u0433\u043e\u043d\u043a\u0443 \u0442\u0440\u0451\u0445 \u0430\u0432\u0442\u043e\u043c\u043e\u0431\u0438\u043b\u0435\u0439. \u0412 \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043c\u0430\u0448\u0438\u043d\u0430 \u043b\u0438\u0431\u043e \u0434\u0432\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u0432\u043f\u0435\u0440\u0451\u0434, \u043b\u0438\u0431\u043e \u043d\u0435\u0442. \u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u043d\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u043e\u0431\u0438\u043b\u044f\u043c\u0438 \u043f\u0443\u0442\u044c. \u0427\u0435\u0440\u0435\u0437 \u043f\u044f\u0442\u044c \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u043e\u0432 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0433\u043e\u043d\u043a\u0430 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0432\u044b\u0432\u043e\u0434\u0430:<\/p>\n<pre><code class=\"bash\"> -  - -  - -   - -  - -  - - -   - - -  - -  - - -   - - - -  - - -  - - - -   - - - -  - - - -  - - - - - <\/code><\/pre>\n<p>  \u0422\u0435\u043a\u0441\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b:<\/p>\n<pre><code class=\"python\">from random import random  time = 5 car_positions = [1, 1, 1]  while time:     # decrease time     time -= 1      print ''     for i in range(len(car_positions)):         # move car         if random() &gt; 0.3:             car_positions[i] += 1          # draw car         print '-' * car_positions[i] <\/code><\/pre>\n<p>  \u041a\u043e\u0434 \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u0435\u043d. \u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0431\u044b\u043b\u0430 \u0431\u044b \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u2013 \u043e\u043d\u0430 \u0431\u044b \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u043b\u0430, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0430 \u043d\u0435 \u0442\u043e, \u043a\u0430\u043a \u044d\u0442\u043e \u043d\u0430\u0434\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<h4>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/h4>\n<p>  \u0414\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0441\u0442\u0438\u0447\u044c, \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u044f \u043a\u043e\u0434 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"python\">from random import random  def move_cars():     for i, _ in enumerate(car_positions):         if random() &gt; 0.3:             car_positions[i] += 1  def draw_car(car_position):     print '-' * car_position  def run_step_of_race():     global time     time -= 1     move_cars()  def draw():     print ''     for car_position in car_positions:         draw_car(car_position)  time = 5 car_positions = [1, 1, 1]  while time:     run_step_of_race()     draw() <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0446\u0438\u043a\u043b. \u00ab\u0415\u0441\u043b\u0438 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0432\u0440\u0435\u043c\u044f, \u043f\u0440\u043e\u0439\u0434\u0451\u043c \u043e\u0434\u0438\u043d \u0448\u0430\u0433 \u0433\u043e\u043d\u043a\u0438 \u0438 \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u0421\u043d\u043e\u0432\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0432\u0440\u0435\u043c\u044f\u00bb. \u0415\u0441\u043b\u0438 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044e \u043d\u0430\u0434\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0448\u0430\u0433 \u0433\u043e\u043d\u043a\u0438, \u043e\u043d \u0441\u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0447\u0435\u0441\u0442\u044c \u0435\u0433\u043e \u043a\u043e\u0434 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e.<\/p>\n<p>  \u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b, \u043a\u043e\u0434 \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0435\u0442 \u0441\u0430\u043c \u0441\u0435\u0431\u044f.<\/p>\n<p>  \u0420\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u0435\u043b\u0430\u0435\u0442 \u043a\u043e\u0434 \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u043c. \u042d\u0442\u043e\u0442 \u043f\u0440\u0438\u0451\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u043e \u043b\u0438\u0448\u044c \u043a\u0430\u043a \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u041e\u043d\u0438 \u0443\u043f\u0430\u043a\u043e\u0432\u044b\u0432\u0430\u044e\u0442 \u043a\u043e\u0434, \u043d\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u044e\u0442 \u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c. \u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u043b\u0438\u044f\u044e\u0442 \u043d\u0430 \u043e\u043a\u0440\u0443\u0436\u0430\u044e\u0449\u0438\u0439 \u0438\u0445 \u043a\u043e\u0434 \u0438 \u043c\u0435\u043d\u044f\u044e\u0442 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0430 \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u0435\u043c\u0443 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043d\u0430\u0439\u0442\u0438, \u043e\u0442\u043a\u0443\u0434\u0430 \u043e\u043d\u0430 \u0432\u0437\u044f\u043b\u0430\u0441\u044c.<\/p>\n<p>  \u0412\u043e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b:<\/p>\n<pre><code class=\"python\">from random import random  def move_cars(car_positions):     return map(lambda x: x + 1 if random() &gt; 0.3 else x,                car_positions)  def output_car(car_position):     return '-' * car_position  def run_step_of_race(state):     return {'time': state['time'] - 1,             'car_positions': move_cars(state['car_positions'])}  def draw(state):     print ''     print '\\n'.join(map(output_car, state['car_positions']))  def race(state):     draw(state)     if state['time']:         race(run_step_of_race(state))  race({'time': 5,       'car_positions': [1, 1, 1]}) <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u0434 \u0440\u0430\u0437\u0431\u0438\u0442 \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0422\u043e\u043c\u0443 \u0435\u0441\u0442\u044c \u0442\u0440\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430. \u041f\u0435\u0440\u0432\u044b\u0439 \u2013 \u043d\u0435\u0442 \u0440\u0430\u0441\u0448\u0430\u0440\u0435\u043d\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445. time \u0438 car_positions \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u044f\u043c\u0438\u043a\u043e\u043c \u0432 race(). \u0412\u0442\u043e\u0440\u043e\u0435 \u2013 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b. \u0422\u0440\u0435\u0442\u044c\u0435 \u2013 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043d\u0435 \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f. \u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 run_step_of_race() \u043f\u0440\u043e\u0434\u0435\u043b\u044b\u0432\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0448\u0430\u0433, \u043e\u043d \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u043e\u043f\u044f\u0442\u044c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439.<\/p>\n<p>  \u0412\u043e\u0442 \u0432\u0430\u043c \u0434\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 zero() \u0438 one():<\/p>\n<pre><code class=\"python\">def zero(s):     if s[0] == &quot;0&quot;:         return s[1:]  def one(s):     if s[0] == &quot;1&quot;:         return s[1:] <\/code><\/pre>\n<p>  zero() \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 s. \u0415\u0441\u043b\u0438 \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u2013 0, \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0441\u0442\u0430\u0442\u043e\u043a \u0441\u0442\u0440\u043e\u043a\u0438. \u0415\u0441\u043b\u0438 \u043d\u0435\u0442 \u2013 \u0442\u043e\u0433\u0434\u0430 None. one() \u0434\u0435\u043b\u0430\u0435\u0442 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u2013 1.<\/p>\n<p>  \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e rule_sequence(). \u041e\u043d\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0439-\u043f\u0440\u0430\u0432\u0438\u043b, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 zero \u0438 one. \u041e\u043d\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f \u0435\u043c\u0443 \u0441\u0442\u0440\u043e\u043a\u0443. \u0415\u0441\u043b\u0438 \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u043e None, \u0442\u043e \u0431\u0435\u0440\u0451\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0451\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e. \u0418 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435. \u0415\u0441\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f None, rule_sequence() \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 None. \u0418\u043d\u0430\u0447\u0435 \u2013 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0430.<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"python\">print rule_sequence('0101', [zero, one, zero]) # =&gt; 1  print rule_sequence('0101', [zero, zero]) # =&gt; None <\/code><\/pre>\n<p>  \u0418\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f rule_sequence():<\/p>\n<pre><code class=\"python\">def rule_sequence(s, rules):     for rule in rules:         s = rule(s)         if s == None:             break      return s <\/code><\/pre>\n<p>  <b>\u0423\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0435 3<\/b>. \u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0446\u0438\u043a\u043b. \u041f\u0435\u0440\u0435\u043f\u0438\u0448\u0438\u0442\u0435 \u0435\u0433\u043e \u0432 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u043c \u0432\u0438\u0434\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041c\u043e\u0451 \u0440\u0435\u0448\u0435\u043d\u0438\u0435:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">def rule_sequence(s, rules):     if s == None or not rules:         return s     else:         return rule_sequence(rules[0](s), rules[1:]) <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h4>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u044b (pipelines)<\/h4>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u0434\u0440\u0443\u0433\u043e\u0439 \u0432\u0438\u0434 \u0446\u0438\u043a\u043b\u043e\u0432 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043f\u0440\u0438\u0451\u043c\u0430 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440.<\/p>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0446\u0438\u043a\u043b \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u043b\u043e\u0432\u0430\u0440\u0438, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u0438\u043c\u044f, \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0443 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0438 \u0441\u0442\u0430\u0442\u0443\u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0433\u0440\u0443\u043f\u043f.<\/p>\n<pre><code class=\"python\">bands = [{'name': 'sunset rubdown', 'country': 'UK', 'active': False},          {'name': 'women', 'country': 'Germany', 'active': False},          {'name': 'a silver mt. zion', 'country': 'Spain', 'active': True}]  def format_bands(bands):     for band in bands:         band['country'] = 'Canada'         band['name'] = band['name'].replace('.', '')         band['name'] = band['name'].title()  format_bands(bands)  print bands # =&gt; [{'name': 'Sunset Rubdown', 'active': False, 'country': 'Canada'}, #     {'name': 'Women', 'active': False, 'country': 'Canada' }, #     {'name': 'A Silver Mt Zion', 'active': True, 'country': 'Canada'}] <\/code><\/pre>\n<p>  \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u00abformat\u00bb \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043e\u0431\u0449\u0435\u0435. \u0418 \u0432\u043e\u043e\u0431\u0449\u0435, \u043a\u043e\u0434 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0439\u0441\u0442\u0432\u043e. \u0412 \u043e\u0434\u043d\u043e\u043c \u0446\u0438\u043a\u043b\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u0442\u0440\u0438 \u0440\u0430\u0437\u043d\u044b\u0435 \u0432\u0435\u0449\u0438. \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0430 &#8216;country&#8217; \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430 &#8216;Canada&#8217;. \u0423\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u0447\u043a\u0438 \u0438 \u043f\u0435\u0440\u0432\u0430\u044f \u0431\u0443\u043a\u0432\u0430 \u0438\u043c\u0435\u043d\u0438 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u0437\u0430\u0433\u043b\u0430\u0432\u043d\u0443\u044e. \u0421\u043b\u043e\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u043a\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u0434\u0435\u043b\u0430\u0442\u044c, \u0438 \u0441\u043b\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0434\u0435\u043b\u0430\u0435\u0442 \u043b\u0438 \u043e\u043d \u044d\u0442\u043e. \u0415\u0433\u043e \u0442\u044f\u0436\u0435\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u0442\u044c.<\/p>\n<p>  \u0421\u0440\u0430\u0432\u043d\u0438\u0442\u0435:<\/p>\n<pre><code class=\"python\">print pipeline_each(bands, [set_canada_as_country,                             strip_punctuation_from_name,                             capitalize_names]) <\/code><\/pre>\n<p>  \u0412\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e. \u0412\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c\u0438, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d\u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u044b \u0432 \u0446\u0435\u043f\u043e\u0447\u043a\u0443. \u0412\u044b\u0445\u043e\u0434 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u2013 \u0432\u0445\u043e\u0434 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439. \u0418\u0445 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0438 \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u0442\u044c.<\/p>\n<p>  pipeline_each() \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u0442 \u0433\u0440\u0443\u043f\u043f\u044b \u043f\u043e \u043e\u0434\u043d\u043e\u0439, \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442 \u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u0432\u0440\u043e\u0434\u0435 set_canada_as_country(). \u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u043e \u0432\u0441\u0435\u043c \u0433\u0440\u0443\u043f\u043f\u0430\u043c, pipeline_each() \u0434\u0435\u043b\u0430\u0435\u0442 \u0438\u0437 \u043d\u0438\u0445 \u0441\u043f\u0438\u0441\u043e\u043a \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439.<\/p>\n<p>  \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<pre><code class=\"python\">def assoc(_d, key, value):     from copy import deepcopy     d = deepcopy(_d)     d[key] = value     return d  def set_canada_as_country(band):     return assoc(band, 'country', &quot;Canada&quot;)  def strip_punctuation_from_name(band):     return assoc(band, 'name', band['name'].replace('.', ''))  def capitalize_names(band):     return assoc(band, 'name', band['name'].title()) <\/code><\/pre>\n<p>  \u041a\u0430\u0436\u0434\u0430\u044f \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043b\u044e\u0447 \u0433\u0440\u0443\u043f\u043f\u044b \u0441 \u043d\u043e\u0432\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c. \u0411\u0435\u0437 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u044d\u0442\u043e \u0442\u044f\u0436\u0435\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0440\u0435\u0448\u0430\u0435\u043c \u044d\u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e assoc(). \u041e\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 deepcopy() \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u043f\u0438\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u044f. \u041a\u0430\u0436\u0434\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043f\u0438\u044e \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u044d\u0442\u0443 \u043a\u043e\u043f\u0438\u044e.<\/p>\n<p>  \u0412\u0441\u0451 \u0432\u0440\u043e\u0434\u0435 \u043a\u0430\u043a \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e. \u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u0449\u0438\u0449\u0435\u043d\u044b \u043e\u0442 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439. \u041d\u043e \u0432 \u043a\u043e\u0434\u0435 \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0441\u0442\u0430 \u0434\u043b\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0434\u0430\u043d\u043d\u044b\u0445. \u0412 strip_punctuation_from_name() \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0438\u043c\u044f \u0431\u0435\u0437 \u0442\u043e\u0447\u0435\u043a \u0447\u0435\u0440\u0435\u0437 \u0432\u044b\u0437\u043e\u0432 calling replace() \u0441 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u043c \u0438\u043c\u0435\u043d\u0435\u043c. \u0412 capitalize_names() \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0438\u043c\u044f \u0441 \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u0440\u043e\u043f\u0438\u0441\u043d\u043e\u0439 \u0431\u0443\u043a\u0432\u043e\u0439 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 title() \u0438 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u043c\u0435\u043d\u0438. \u0415\u0441\u043b\u0438 replace \u0438 time \u043d\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b, \u0442\u043e \u0438 strip_punctuation_from_name() \u0441 capitalize_names() \u043d\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b.<\/p>\n<p>  \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u043e\u043d\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b. \u0412 Python \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b. \u042d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441 \u043a\u043e\u043f\u0438\u044f\u043c\u0438 \u0441\u0442\u0440\u043e\u043a. \u0423\u0444\u0444, \u0441\u043b\u0430\u0432\u0430 \u0431\u043e\u0433\u0443.<\/p>\n<p>  \u0422\u0430\u043a\u043e\u0439 \u043a\u043e\u043d\u0442\u0440\u0430\u0441\u0442 \u043c\u0435\u0436\u0434\u0443 \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438 \u0438 \u0441\u043b\u043e\u0432\u0430\u0440\u044f\u043c\u0438 (\u0438\u0445 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0441\u0442\u044c\u044e) \u0432 Python \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 \u044f\u0437\u044b\u043a\u043e\u0432 \u0442\u0438\u043f\u0430 Clojure. \u0422\u0430\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0443 \u043d\u0435 \u043d\u0430\u0434\u043e \u0434\u0443\u043c\u0430\u0442\u044c, \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442 \u043b\u0438 \u043e\u043d \u0434\u0430\u043d\u043d\u044b\u0435. \u041d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442.<\/p>\n<p>  <b>\u0423\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0435 4<\/b>. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e pipeline_each. \u0417\u0430\u0434\u0443\u043c\u0430\u0439\u0442\u0435\u0441\u044c \u043d\u0430\u0434 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439. \u0413\u0440\u0443\u043f\u043f\u044b \u2013 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435, \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u043f\u043e \u043e\u0434\u043d\u043e\u0439 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f. \u0417\u0430\u0442\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u043f\u043e \u043e\u0434\u043d\u043e\u0439 \u0448\u0442\u0443\u0447\u043a\u0435 \u0434\u043b\u044f \u0432\u0442\u043e\u0440\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041c\u043e\u0451 \u0440\u0435\u0448\u0435\u043d\u0438\u0435:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">def pipeline_each(data, fns):     return reduce(lambda a, x: map(x, a),                   fns,                   data) <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0412\u0441\u0435 \u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043c\u0435\u043d\u044f\u044e\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u043f\u043e\u043b\u0435 \u0443 \u0433\u0440\u0443\u043f\u043f\u044b. call() \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e. \u041e\u043d\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u043a\u043b\u044e\u0447, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0430.<\/p>\n<pre><code class=\"python\">set_canada_as_country = call(lambda x: 'Canada', 'country') strip_punctuation_from_name = call(lambda x: x.replace('.', ''), 'name') capitalize_names = call(str.title, 'name')  print pipeline_each(bands, [set_canada_as_country,                             strip_punctuation_from_name,                             capitalize_names]) <\/code><\/pre>\n<p>  \u0418\u043b\u0438, \u0436\u0435\u0440\u0442\u0432\u0443\u044f \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u044c\u044e:<\/p>\n<pre><code class=\"python\">print pipeline_each(bands, [call(lambda x: 'Canada', 'country'),                             call(lambda x: x.replace('.', ''), 'name'),                             call(str.title, 'name')]) <\/code><\/pre>\n<p>  \u041a\u043e\u0434 \u0434\u043b\u044f call():<\/p>\n<pre><code class=\"python\">def assoc(_d, key, value):     from copy import deepcopy     d = deepcopy(_d)     d[key] = value     return d  def call(fn, key):     def apply_fn(record):         return assoc(record, key, fn(record.get(key)))     return apply_fn <\/code><\/pre>\n<p>  \u0427\u0442\u043e \u0442\u0443\u0442 \u0443 \u043d\u0430\u0441 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442.<\/p>\n<p>  \u041e\u0434\u0438\u043d. call \u2013 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0441\u0448\u0435\u0433\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0430, \u0442.\u043a. \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u0440\u0443\u0433\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a\u0430\u043a \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/p>\n<p>  \u0414\u0432\u0430. apply_fn() \u043f\u043e\u0445\u043e\u0436\u0430 \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u044c (\u0433\u0440\u0443\u043f\u043f\u0443). \u0418\u0449\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 record[key]. \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442 fn. \u041f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u043a\u043e\u043f\u0438\u044e \u0437\u0430\u043f\u0438\u0441\u0438 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0435\u0451.<\/p>\n<p>  \u0422\u0440\u0438. call \u0441\u0430\u043c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442. \u0412\u0441\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0434\u0435\u043b\u0430\u0435\u0442 apply_fn(). \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f pipeline_each(), \u043e\u0434\u0438\u043d \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 apply_fn() \u0437\u0430\u0434\u0430\u0451\u0442 &#8216;country&#8217; \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 &#8216;Canada&#8217;. \u0414\u0440\u0443\u0433\u043e\u0439 \u2013 \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u0443\u044e \u0431\u0443\u043a\u0432\u0443 \u043f\u0440\u043e\u043f\u0438\u0441\u043d\u043e\u0439.<\/p>\n<p>  \u0427\u0435\u0442\u044b\u0440\u0435. \u041f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 apply_fn() \u0444\u0443\u043d\u043a\u0446\u0438\u0438 fn \u0438 key \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438. \u042d\u0442\u043e \u043d\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b apply_fn() \u0438 \u043d\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435. \u041d\u043e \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043d\u0438\u043c \u0431\u0443\u0434\u0435\u0442. \u041f\u0440\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u043d\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d\u0430 \u0437\u0430\u043c\u044b\u043a\u0430\u0435\u0442 \u2013 \u0442\u0435, \u0447\u0442\u043e \u0431\u044b\u043b\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0441\u043d\u0430\u0440\u0443\u0436\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438. \u041f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438\u0449\u0443\u0442\u0441\u044f \u0441\u0440\u0435\u0434\u0438 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445, \u0437\u0430\u0442\u0435\u043c \u0441\u0440\u0435\u0434\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0430 \u0437\u0430\u0442\u0435\u043c \u0441\u0440\u0435\u0434\u0438 \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 \u0437\u0430\u043c\u043a\u043d\u0443\u0442\u044b\u0435. \u0422\u0430\u043c \u0438 \u043d\u0430\u0439\u0434\u0443\u0442\u0441\u044f fn \u0438 key.<\/p>\n<p>  \u041f\u044f\u0442\u044c. \u0412 call \u043d\u0435\u0442 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u044f \u0433\u0440\u0443\u043f\u043f. \u042d\u0442\u043e \u043e\u0442\u0442\u043e\u0433\u043e, \u0447\u0442\u043e call \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043b\u044e\u0431\u044b\u0445 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u043e\u0432, \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442 \u0438\u0445 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e. \u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0441\u0442\u0440\u043e\u0438\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043e\u0431\u0449\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043f\u0440\u0438\u0433\u043e\u0434\u043d\u044b\u0445 \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0439 \u0438 \u0434\u043b\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  \u041c\u043e\u043b\u043e\u0434\u0446\u043e\u043c. \u0417\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u044f, \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u044b\u0441\u0448\u0435\u0433\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0438 \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u2013 \u0432\u0441\u0451 \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u0430\u0440\u0430\u0433\u0440\u0430\u0444\u0430\u0445. \u041c\u043e\u0436\u043d\u043e \u0438 \u0447\u0430\u0439\u043a\u0443 \u0441 \u043f\u0435\u0447\u0435\u043d\u044c\u043a\u0430\u043c\u0438 \u0432\u044b\u043f\u0438\u0442\u044c.<\/p>\n<p>  \u041e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0435\u0449\u0451 \u043e\u0434\u043d\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0433\u0440\u0443\u043f\u043f. \u0423\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u0451, \u043a\u0440\u043e\u043c\u0435 \u0438\u043c\u0435\u043d\u0438 \u0438 \u0441\u0442\u0440\u0430\u043d\u044b. \u0424\u0443\u043d\u043a\u0446\u0438\u044f extract_name_and_country():<\/p>\n<pre><code class=\"python\">def extract_name_and_country(band):     plucked_band = {}     plucked_band['name'] = band['name']     plucked_band['country'] = band['country']     return plucked_band  print pipeline_each(bands, [call(lambda x: 'Canada', 'country'),                             call(lambda x: x.replace('.', ''), 'name'),                             call(str.title, 'name'),                             extract_name_and_country])  # =&gt; [{'name': 'Sunset Rubdown', 'country': 'Canada'}, #     {'name': 'Women', 'country': 'Canada'}, #     {'name': 'A Silver Mt Zion', 'country': 'Canada'}] <\/code><\/pre>\n<p>  extract_name_and_country() \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043e\u0431\u043e\u0431\u0449\u0451\u043d\u043d\u043e\u043c \u0432\u0438\u0434\u0435 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c pluck(). \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u0431\u044b \u043e\u043d\u0430 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">print pipeline_each(bands, [call(lambda x: 'Canada', 'country'),                             call(lambda x: x.replace('.', ''), 'name'),                             call(str.title, 'name'),                             pluck(['name', 'country'])]) <\/code><\/pre>\n<p>  <b>\u0423\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0435 5<\/b>. pluck \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u043a\u043b\u044e\u0447\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0434\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0438\u0437 \u0437\u0430\u043f\u0438\u0441\u0435\u0439. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0435\u0451 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c. \u042d\u0442\u043e \u0431\u0443\u0434\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0441\u0448\u0435\u0433\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0430.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041c\u043e\u0451 \u0440\u0435\u0448\u0435\u043d\u0438\u0435:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">def pluck(keys):     def pluck_fn(record):         return reduce(lambda a, x: assoc(a, x, record[x]),                       keys,                       {})     return pluck_fn <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0418 \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c?<\/p>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434 \u0445\u043e\u0440\u043e\u0448\u043e \u0441\u043e\u0447\u0435\u0442\u0430\u0435\u0442\u0441\u044f \u0441 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u043c. \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0437 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043b\u044e\u0431\u043e\u043c \u044f\u0437\u044b\u043a\u0435. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0438 \u0432\u044b \u0434\u043b\u044f \u0441\u0432\u043e\u0435\u0433\u043e \u043a\u043e\u0434\u0430. <\/p>\n<p>  \u0412\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u0435 \u043f\u0440\u043e \u041c\u0430\u0448\u0443, \u041f\u0435\u0442\u044e \u0438 \u0412\u0430\u0441\u044e. \u041f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u0435 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e \u0441\u043f\u0438\u0441\u043a\u0430\u043c \u0432 map \u0438 reduces.<\/p>\n<p>  \u0412\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u0435 \u0433\u043e\u043d\u043a\u0438. \u0420\u0430\u0437\u0431\u0435\u0439\u0442\u0435 \u043a\u043e\u0434 \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0438 \u0441\u0434\u0435\u043b\u0430\u0439\u0442\u0435 \u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c\u0438. \u041f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u0435 \u0446\u0438\u043a\u043b \u0432 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u044e.<\/p>\n<p>  \u0412\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u0435 \u043f\u0440\u043e \u0433\u0440\u0443\u043f\u043f\u044b. \u041f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440.   \t<\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/257903\/\"> http:\/\/habrahabr.ru\/post\/257903\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u0420\u0430\u0441\u0441\u0443\u0436\u0434\u0430\u044f \u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438, \u043b\u044e\u0434\u0438 \u0447\u0430\u0441\u0442\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u0443\u0447\u0443 \u00ab\u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445\u00bb \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a. \u041d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0445\u0432\u043e\u0441\u0442\u043e\u0432\u043e\u0439 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438. \u042d\u0442\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u044f\u0437\u044b\u043a\u0430, \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0449\u0438\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u041e\u043d\u0438 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u044e\u0442 \u043c\u0430\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043a\u0430\u0440\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432\u044b\u0441\u0448\u0435\u0433\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0430. \u042d\u0442\u043e \u043f\u0440\u0438\u0451\u043c\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0435\u0441\u044f \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u041e\u043d\u0438 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u044e\u0442 \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u043d\u0438\u0435, \u043b\u0435\u043d\u0438\u0432\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0438 \u0434\u0435\u0442\u0435\u0440\u043c\u0435\u043d\u0438\u0437\u043c. \u042d\u0442\u043e \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c.<\/p>\n<p>  \u0417\u0430\u0431\u0435\u0439\u0442\u0435. \u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u0438\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e\u043c: \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435\u043c \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0445 \u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432. \u041e\u043d \u043d\u0435 \u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u043d\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0438 \u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0435\u0441\u044f \u0432\u043d\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0412\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u00ab\u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u00bb \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0438\u0437 \u044d\u0442\u043e\u0433\u043e. <\/p>\n<p>  \u041d\u0435\u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f:<\/p>\n<pre><code class=\"python\">a = 0 def increment1():     global a     a += 1 <\/code><\/pre>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f:<\/p>\n<pre><code class=\"python\">def increment2(a):     return a + 1 <\/code><\/pre>\n<p>  \u0412\u043c\u0435\u0441\u0442\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u043e\u0432 \u043f\u043e \u0441\u043f\u0438\u0441\u043a\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 map \u0438 reduce  <\/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-257156","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/257156","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=257156"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/257156\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=257156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=257156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=257156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}