{"id":2804,"date":"2025-08-23T18:06:40","date_gmt":"2025-08-23T15:06:40","guid":{"rendered":"http:\/\/csnotes.ru\/?p=2804"},"modified":"2025-08-23T21:41:45","modified_gmt":"2025-08-23T18:41:45","slug":"%d0%be%d0%b4%d0%bd%d0%be%d1%81%d1%82%d1%80%d0%be%d1%87%d0%bd%d0%b8%d0%ba%d0%b8-python-comprehension-%d0%b8-%d1%82-%d0%b4","status":"publish","type":"post","link":"https:\/\/csnotes.ru\/?p=2804","title":{"rendered":"\u041e\u0434\u043d\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u0438\u043a\u0438 Python: comprehension \u0438 \u0442.\u0434."},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u041e\u0434\u043d\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u044b\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0432 Python \u0434\u0435\u043b\u0430\u044e\u0442 \u043a\u043e\u0434 \u043a\u0440\u0430\u0442\u043a\u0438\u043c \u0438 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u043c. \u041d\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0443\u043b\u0443\u0447\u0448\u0430\u044e\u0442 \u0435\u0433\u043e \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u044c.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u0420\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0430 \u043a\u043e\u0440\u0442\u0435\u0436\u0430<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b\/\u0447\u0438\u0441\u043b\u0430\/\u0441\u043b\u043e\u0432\u0430 \u0431\u0443\u0434\u0443\u0442 \u0432\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u0431\u0435\u043b.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>x, y, z = input().strip().split()<\/strong>\nprint(f\"{x=}, {y=}, {z=}\")<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">map()<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0431\u0435\u0437 \u043e\u0431\u0445\u043e\u0434\u0430 \u0432 \u0446\u0438\u043a\u043b\u0435.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432 \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0439\n<strong>x, y, z = map(int, (x, y, z))<\/strong>\n\n# \u0412\u043e\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\n<strong>x, y, z = map(lambda a: a**2, (x, y, z))<\/strong><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">reduce()<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043a \u0434\u0432\u0443\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u0430 <strong>\u043a\u0443\u043c\u0443\u043b\u044f\u0442\u0438\u0432\u043d\u043e<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from functools import reduce\n\nx, y, z = map(int, input().strip().split())\n\n# \u041f\u043e\u043f\u0430\u0440\u043d\u043e\u0435 \u043f\u0435\u0440\u0435\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u0432\u0443\u0445 \u043f\u0435\u0440\u0432\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432\n# \u041f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0432\u044b\u0445 \u0434\u0432\u0443\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0437\u0430\u0442\u0435\u043c \u0443\u043c\u043d\u043e\u0436\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0442\u0440\u0435\u0442\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438 \u0442.\u0434.\n<strong>volume = reduce(lambda a, b: a * b, (x, y, z))<\/strong>\n\nprint(volume)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">List Comprehension<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u043f\u0438\u0441\u043a\u0430 &#8211; \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u0432\u0438\u0434\u0430:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>l = &#91;<strong>x for x in<\/strong> range(10)]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441 \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>names = &#91;'Christoff', 'Ademar', 'Teya', 'Stephania', 'Arhiph']\n\n# \u041e\u0442\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0438\u043c\u0435\u043d\u0430 \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430, \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0441 \u0431\u0443\u043a\u0432\u044b \"A\"\n<strong>names_starts_a = &#91;name for name in names if name.startswith('A')]<\/strong>\n\nprint(names_starts_a)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">filter()<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043f\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044e:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>names = &#91;'Christoff', 'Ademar', 'Teya', 'Stephania', 'Arhiph']\n\n# \u041e\u0442\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0438\u043c\u0435\u043d\u0430 \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430, \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0441 \u0431\u0443\u043a\u0432\u044b \"A\"\n<strong>names_starts_a = filter(lambda a: a.startswith('A'), names)<\/strong>\n\n# \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b filter - \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u043c \u0435\u0433\u043e \u0432 list\nprint(<strong>list(names_starts_a)<\/strong>)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u041a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0440\u0435\u0437\u0430<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u0421\u0443\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u043f\u0438\u0438 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d \u0434\u0440\u0443\u0433\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u0442\u0430\u043a\u0438\u043c \u0436\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c. \u041f\u0440\u043e\u0441\u0442\u043e\u0435 \u043f\u0440\u0438\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u0435 \u0432\u0438\u0434\u0430 l1 = l2 \u041d\u0415 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 (\u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0438 \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 l1 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0438 l2).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>l1 = &#91;1, 3, 5, 7]\n\n<strong>l2 = l1&#91;:]<\/strong>\n\nprint(l1 is l1_copy) # False<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u041d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u0431\u044b\u0432\u0430\u0442\u044c \u043e \u043c\u0435\u0442\u043e\u0434\u0435 .copy() \u0438 .deepcopy().<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u0418\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0440\u0435\u0437\u0430<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>l1 = &#91;1, 3, 5, 7]\n\n<strong>l2 = l1&#91;::-1]<\/strong>\n\nprint(l2) # &#91;7, 5, 3, 1]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">all()<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u0424\u0443\u043d\u043a\u0446\u0438\u044f all() \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e <strong>\u0432\u0441\u0435<\/strong> \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f True. \u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f True, \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u0435\u0440\u043d\u0435\u0442 False.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a = b = c = d = True\nif <strong>all((a, b, c, d))<\/strong>:\n    print(\"All True!!!\")<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">any()<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u0424\u0443\u043d\u043a\u0446\u0438\u044f any() \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e <strong>\u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d<\/strong> \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f True.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>d = True\na = b = c = None\nif <strong>any((a, b, c, d))<\/strong>:\n    print(\"Any True!!!\")<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u0422\u0435\u0440\u043d\u0430\u0440\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u042d\u0442\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u0432\u0438\u0434\u0430: A if CONDITION else B. \u0417\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u043c\u043d\u043e\u0433\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u0443\u044e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e if-else.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">n = 1<br>admin_email = <strong>\"agner@mail.ru\" if n > 2 else \"xxx@xxx.xx\"<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041e\u0434\u043d\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u044b\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0432 Python \u0434\u0435\u043b\u0430\u044e\u0442 \u043a\u043e\u0434 \u043a\u0440\u0430\u0442\u043a\u0438\u043c \u0438 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u043c. \u041d\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0443\u043b\u0443\u0447\u0448\u0430\u044e\u0442 \u0435\u0433\u043e \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u044c. \u0420\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0430 \u043a\u043e\u0440\u0442\u0435\u0436\u0430 \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b\/\u0447\u0438\u0441\u043b\u0430\/\u0441\u043b\u043e\u0432\u0430 \u0431\u0443\u0434\u0443\u0442 \u0432\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u0431\u0435\u043b. map() \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0431\u0435\u0437 \u043e\u0431\u0445\u043e\u0434\u0430 \u0432 \u0446\u0438\u043a\u043b\u0435. reduce() \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043a \u0434\u0432\u0443\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043a\u0443\u043c\u0443\u043b\u044f\u0442\u0438\u0432\u043d\u043e List Comprehension \u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u043f\u0438\u0441\u043a\u0430 &#8211; \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,24],"tags":[130,129],"class_list":["post-2804","post","type-post","status-publish","format-standard","hentry","category-python","category-tech","tag--python","tag-129"],"views":119,"_links":{"self":[{"href":"https:\/\/csnotes.ru\/index.php?rest_route=\/wp\/v2\/posts\/2804","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/csnotes.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/csnotes.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/csnotes.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/csnotes.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2804"}],"version-history":[{"count":8,"href":"https:\/\/csnotes.ru\/index.php?rest_route=\/wp\/v2\/posts\/2804\/revisions"}],"predecessor-version":[{"id":2821,"href":"https:\/\/csnotes.ru\/index.php?rest_route=\/wp\/v2\/posts\/2804\/revisions\/2821"}],"wp:attachment":[{"href":"https:\/\/csnotes.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2804"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/csnotes.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2804"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/csnotes.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2804"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}