{"id":309480,"date":"2020-09-04T15:00:56","date_gmt":"2020-09-04T15:00:56","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=309480"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=309480","title":{"rendered":"\u041f\u0430\u0439\u043f\u043b\u0430\u0439\u043d\u044b \u0438 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0437\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u0432 Python"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/517780\/\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/vz\/vl\/to\/vzvltol9fg_rtmjjhtolrc6c09e.png\"><\/p>\n<p>  <\/p>\n<p>\u041e\u0434\u043d\u043e \u0438\u0437 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u0434\u043e\u0441\u0442\u043e\u0438\u043d\u0441\u0442\u0432 Python \u2014 \u0435\u0433\u043e \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c. \u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u044f\u0437\u044b\u043a\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0434 \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u041d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u0432 Python \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0443\u044e \u044f\u0437\u044b\u043a\u0430, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 &quot;\u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0439&quot; \u0438 \u0438\u0445 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u043b\u044c\u044e \u0432\u043e\u0434\u0443 \u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u0441 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u043f\u043e \u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u041f\u0440\u0438\u0448\u0451\u043b \u0432\u043e \u043c\u043d\u043e\u0433\u043e\u043c \u0437\u0430 \u043a\u0440\u0438\u0442\u0438\u043a\u043e\u0439. \u041f\u0440\u0438\u044f\u0442\u043d\u043e\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u044f!<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h2 id=\"kratko-o-fp-v-python-i-pochemu-ne-hvataet-payplaynov-na-primere\">\u041a\u0440\u0430\u0442\u043a\u043e \u043e \u0424\u041f \u0432 Python \u0438 \u043f\u043e\u0447\u0435\u043c\u0443 \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d\u043e\u0432 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435<\/h2>\n<p>  <\/p>\n<p>\u0412 Python \u0438\u0437 \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u0435\u0441\u0442\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u044b\u0435 map(), reduce(), filter(), \u043b\u044f\u043c\u0431\u0434\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b. \u041c\u0430\u043b\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u044b\u043c \u0441 \u044d\u0442\u0438\u043c \u0432\u0441\u0435\u043c \u0441\u043e\u0432\u0435\u0442\u0443\u044e <a href=\"https:\/\/habr.com\/ru\/post\/517438\/\">\u0434\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e<\/a>. \u0412 \u0446\u0435\u043b\u043e\u043c \u044d\u0442\u043e \u043e\u043d\u043e \u0432\u0441\u0451 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0434 \u0441\u043f\u0438\u0441\u043a\u0430\u043c\u0438, \u043a\u043e\u0440\u0442\u0435\u0436\u0430\u043c\u0438, \u0438 \u0442\u0434. \u041e\u0447\u0435\u043d\u044c \u0447\u0430\u0441\u0442\u043e(\u0443 \u043c\u0435\u043d\u044f \u0438 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0445 \u043f\u0438\u0442\u043e\u043d\u0438\u0441\u0442\u043e\u0432) \u0442\u043e, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f <del>\u043e\u0434\u043d\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u0438\u043a<\/del> \u2014 \u043f\u043e \u0441\u0443\u0442\u0438 \u043d\u0430\u0431\u043e\u0440 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439, \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<br \/>  <a href=\"https:\/\/www.codewars.com\/kata\/5626b561280a42ecc50000d1\/python\" rel=\"nofollow\">Kata \u0441 CodeWars<\/a>: \u041d\u0430\u0439\u0442\u0438<\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8a2\/419\/6ef\/8a24196ef58b102bdb326c12cb6914e6.svg\" alt=\"$\\forall n \\in [a,b] : n=\\sum_0^{len(n)} n_i ^ i, \\text{ } n_i\\text{ - i-\u0439 \u0440\u0430\u0437\u0440\u044f\u0434 \u0447\u0438\u0441\u043b\u0430 n}$\" data-tex=\"display\"><\/math><\/p>\n<p>  <\/p>\n<p>\u0417\u0430\u0434\u0430\u0447\u043a\u0430 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u044f, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e(\u043d\u043e \u043a \u0441\u0447\u0430\u0441\u0442\u044c\u044e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430), \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043b\u0443\u0447\u0448\u0435 \u0447\u0435\u043c \u0432 \u043b\u043e\u0431 \u043d\u0435\u0442.<\/p>\n<p>  <\/p>\n<p>\u041c\u043e\u0451 \u0440\u0435\u0448\u0435\u043d\u0438\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">def sum_dig_pow(a, b): # range(a, b + 1) will be studied by the function     powered_sum = lambda x: sum([v**(i+1) for i,v in enumerate(map(lambda x: int(x), list(str(x))))])     return [i for i in range(a,b+1) if powered_sum(i)==i]<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u0424\u041f \u043a\u0430\u043a \u0435\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0441\u043a\u043e\u0431\u043e\u0447\u043d\u044b\u0439 \u0430\u0434 &quot;\u0438\u0437\u043d\u0443\u0442\u0440\u0438 \u043d\u0430\u0440\u0443\u0436\u0443&quot;. \u042d\u0442\u043e \u043c\u043e\u0433 \u0431\u044b \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d.<\/p>\n<p>  <\/p>\n<h2 id=\"payplayny-funkciy\">\u041f\u0430\u0439\u043f\u043b\u0430\u0439\u043d\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/h2>\n<p>  <\/p>\n<p>\u041f\u043e\u0434 \u0441\u0438\u043c \u044f \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u044e \u0442\u0430\u043a\u043e\u0435 \u0432 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 (\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 &quot;|&quot; \u2014 \u043b\u0438\u0447\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u0435):<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># f3(f2(f1(x))) f1 | f2 | f3 &gt;&gt; x pipeline = f1 | f2 | f3  pipeline(x) pipeline2 = f4 | f5 pipeline3 = pipeline | pipeline2 | f6 ...<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u043e\u0433\u0434\u0430 powered_sum \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c(\u043a\u043e\u0434 \u043d\u0435 \u0440\u0430\u0431\u043e\u0447\u0438\u0439):<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">powered_sum = str | list | map(lambda x: int(x), *args) | enumerate | [v**(i+1) for i,v in *args] | sum<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u043f\u043e \u043c\u043d\u0435, \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u043b\u0435\u0433\u0447\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u0438 \u0447\u0438\u0442\u0430\u0442\u044c. args \u0432 \u0446\u0435\u043b\u043e\u043c \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0447\u0443\u0436\u0435\u0440\u043e\u0434\u043d\u043e. \u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043d\u0435 \u043b\u0430\u0437\u044f \u0432 \u043a\u0438\u0448\u043a\u0438 \u043f\u0438\u0442\u043e\u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0435(\u0434\u0430\u043b\u0435\u043a\u043e \u043e\u0442 \u043b\u044e\u0431\u044b\u0445 \u0438\u0434\u0435\u0430\u043b\u043e\u0432):<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">from copy import deepcopy  class CreatePipeline:     def __init__(self, data=None):         self.stack = []         if data is not None:             self.args = data      def __or__(self, f):         new = deepcopy(self)         new.stack.append(f)         return new      def __rshift__(self, v):         new = deepcopy(self)         new.args = v         return new      def call_logic(self, *args):         for f in self.stack:             if type(args) is tuple:                 args = f(*args)             else:                 args = f(args)         return args      def __call__(self, *args):         if 'args' in self.__dict__:             return self.call_logic(self.args)         else:             return self.call_logic(*args)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u044d\u0442\u043e \u043e\u0434\u0438\u043d \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043a\u043e\u0441\u0442\u044b\u043b\u044c, \u0441\u043e\u0441\u0442\u0440\u044f\u043f\u0430\u043d\u043d\u044b\u0439 \u0440\u0430\u0434\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0430, \u0434\u0430\u0436\u0435 \u0431\u0435\u0437 kwargs, \u0445\u043e\u0442\u044f \u0432 \u043f\u043e\u0445\u043e\u0436\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0438 \u043d\u0435 \u0442\u0430\u043a \u0432\u0430\u0436\u043d\u043e.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">pipe = CreatePipeline() powered_sum = pipe | str | list | (lambda l: map(lambda x: int(x), l)) | enumerate | (lambda e: [v**(i+1) for i,v in e]) | sum<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0446\u0435\u043b\u043e\u043c, \u044d\u0442\u0430 \u0448\u0442\u0443\u043a\u0430 \u0434\u0430\u0436\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u0443\u0436\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0438\u043c\u0445\u043e \u043b\u0443\u0447\u0448\u0435, \u0445\u043e\u0442\u044f \u0442\u0430\u043c \u0433\u0434\u0435 \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0442 \u043e\u0434\u043d\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430, \u0430 \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u0443\u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439. <\/p>\n<p>  <\/p>\n<h2 id=\"chastichnoe-primenenie-funkciy\">\u0427\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/h2>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438(\u043a\u043e\u0434 \u043d\u0435 \u0440\u0430\u0431\u043e\u0447\u0438\u0439):<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">def f_partitial (x,y,z):     return x+y+z v = f_partial(1,2) # type(v) = \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0451\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f f_partial, \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0435\u0441\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b: ['z'] print(v(3)) # \u042d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442 print(f_partial(1,2,3))<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0431\u044b\u043b\u0430 \u0431\u044b \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0434\u043b\u044f \u043f\u0430\u0439\u043f\u0430 \u0438 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0440\u0430\u0437\u043d\u043e\u0433\u043e(\u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0430\u043d\u0442\u0430\u0437\u0438\u0438 \u0445\u0432\u0430\u0442\u0438\u0442). \u0422\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u0438\u043c\u0435\u044e\u0449\u0435\u0439\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 pipe \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">powered_sum = pipe | str | list | map(lambda x: int(x)) | enumerate | (lambda e: [v**(i+1) for i,v in e]) | sum # map \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u0435\u0449\u0451 \u0440\u0430\u0437 \u0441\u043e \u0432\u0442\u043e\u0440\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c # map(lambda x: int(x))(\u0434\u0430\u043d\u043d\u044b\u0435) \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435<\/code><\/pre>\n<p>  <\/p>\n<p>map(lambda x: int(x)) \u0432 \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0431\u043e\u043b\u0435\u0435 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e \u0432 \u0446\u0435\u043b\u043e\u043c \u0438 \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439 \u0434\u0430\u043d\u043d\u044b\u0445.<br \/>  \u041a\u0440\u0438\u0432\u0435\u043d\u044c\u043a\u0430\u044f \u043d\u0435\u043f\u043e\u043b\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u044f\u0437\u044b\u043a\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">from inspect import getfullargspec from copy import deepcopy  class CreatePartFunction:     def __init__(self, f):         self.f = f         self.values = []      def __call__(self, *args):         args_f = getfullargspec(self.f)[0]         if len(args) + len(self.values) &lt; len(args_f):             new = deepcopy(self)             new.values = new.values + list(args)             return new         elif len(self.values) + len(args) == len(args_f):             return self.f(*tuple(self.values + list(args)))<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u0434\u0430\u043d\u043d\u043e\u0433\u043e <del>\u043a\u043e\u0441\u0442\u044b\u043b\u044f<\/del> \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># \u043a\u043e\u0441\u0442\u044b\u043b\u044c \u0434\u043b\u044f \u043e\u0431\u0445\u043e\u0434\u0430 \u043f\u043e\u043b\u043e\u043c\u043a\u0438 inspect \u043d\u0430\u0434 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u043c map m = lambda f, l: map(f, l) # \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u043f\u0438\u0442\u043e\u043d\u044c\u0435\u0439 pmap = CreatePartFunction(m) powered_sum = pipe | str | list | pmap(lambda x: int(x)) | enumerate | (lambda e: [v**(i+1) for i,v in e]) | sum<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u0434\u0432\u043e\u0439\u043d\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435(\u0447\u0442\u043e \u0432 \u0446\u0435\u043b\u043e\u043c \u043d\u0435 \u043e\u0441\u043e\u0431\u043e \u043d\u0443\u0436\u043d\u043e), \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0443\u0436\u0435 \u0440\u0430\u0441\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043a\u043e\u0431\u043a\u0438, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043f\u0438\u0442\u043e\u043d \u043f\u043e\u0434\u0443\u043c\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442, \u0442\u043e \u0435\u0441\u0442\u044c:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">def f (x,y,z):     return x+y+z f = CreatePartFunction(f) # \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 print(f(1,2,3)) # \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 print(f(1,2)(3)) print(f(1)(2,3)) # \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 # 2(3) - int \u043d\u0435 callable print(f(1)(2)(3)) # \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 print((f(1)(2))(3))<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"itogi\">\u0418\u0442\u043e\u0433\u0438<\/h2>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u043c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u043f\u043e\u043c\u0435\u0448\u0430\u043b\u0438 \u0431\u044b \u044f\u0437\u044b\u043a\u0443 \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438, \u0441, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c, \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u043c \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u043e\u043c, \u043e\u043d\u0438 \u0432\u0440\u043e\u0434\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043b\u043e\u043c\u0430\u044e\u0442, \u043d\u043e \u043c\u043e\u0433\u0443\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439, \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0443\u0434\u043e\u0431\u043d\u0435\u0435.<\/p>\n<\/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=\"https:\/\/habr.com\/ru\/post\/517780\/\"> https:\/\/habr.com\/ru\/post\/517780\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/517780\/\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/vz\/vl\/to\/vzvltol9fg_rtmjjhtolrc6c09e.png\"><\/p>\n<p>  <\/p>\n<p>\u041e\u0434\u043d\u043e \u0438\u0437 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u0434\u043e\u0441\u0442\u043e\u0438\u043d\u0441\u0442\u0432 Python \u2014 \u0435\u0433\u043e \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c. \u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u044f\u0437\u044b\u043a\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0434 \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u041d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u0432 Python \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0443\u044e \u044f\u0437\u044b\u043a\u0430, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 &quot;\u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0439&quot; \u0438 \u0438\u0445 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u043b\u044c\u044e \u0432\u043e\u0434\u0443 \u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u0441 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u043f\u043e \u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u041f\u0440\u0438\u0448\u0451\u043b \u0432\u043e \u043c\u043d\u043e\u0433\u043e\u043c \u0437\u0430 \u043a\u0440\u0438\u0442\u0438\u043a\u043e\u0439. \u041f\u0440\u0438\u044f\u0442\u043d\u043e\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u044f!<\/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-309480","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/309480","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=309480"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/309480\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=309480"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=309480"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=309480"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}