{"id":309089,"date":"2020-08-27T15:00:11","date_gmt":"2020-08-27T15:00:11","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=309089"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2020-08-27T15:00:11","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=309089","title":{"rendered":"Python \u0438 \u0442\u0435\u043e\u0440\u0438\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432"},"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\/516858\/\">\n<h1 id=\"python-i-teoriya-mnozhestv\">Python \u0438 \u0442\u0435\u043e\u0440\u0438\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/h1>\n<p>  <\/p>\n<p>\u0412 Python \u0435\u0441\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430\u043c\u0438 \u2013 \u044d\u0442\u043e <em>set<\/em>. \u041e\u0431 \u044d\u0442\u043e\u043c \u0442\u0438\u043f\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0432\u044b\u0434\u0435\u0440\u0436\u043a\u0435 \u0438\u0437 \u0442\u0435\u043e\u0440\u0438\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u043f\u043e\u0439\u0434\u0451\u0442 \u0440\u0435\u0447\u044c \u0434\u0430\u043b\u0435\u0435. <\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/9h\/tq\/c0\/9htqc0r1cr_tf1jystcwwayzrww.png\"\/><\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p><em>\u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u0440\u0430\u0437\u0443 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0433\u043e\u0432\u043e\u0440\u043a\u0443, \u0447\u0442\u043e \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0438 \u0432 \u043a\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u0435\u0442 \u043d\u0430 \u043a\u0430\u043a\u0443\u044e-\u043b\u0438\u0431\u043e \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0441\u0442\u0440\u043e\u0433\u043e\u0441\u0442\u044c \u0438 \u043f\u043e\u043b\u043d\u043e\u0442\u0443, \u0441\u043a\u043e\u0440\u0435\u0435 \u044d\u0442\u043e \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u0432 \u044f\u0437\u044b\u043a\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f Python.<\/em><\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"#mnozhestvo\">\u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e<\/a><\/li>\n<li><a href=\"#mnozhestva-v-python\">\u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0432 Python<\/a><br \/> \n<ul>\n<li><a href=\"#heshiruemye-obekty\">\u0425\u0435\u0448\u0438\u0440\u0443\u0435\u043c\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#svoystva-mnozhestv\">\u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/a><br \/> \n<ul>\n<li><a href=\"#prinadlezhnost-mnozhestvu\">\u041f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443<\/a><\/li>\n<li><a href=\"#moschnost-mnozhestva\">\u041c\u043e\u0449\u043d\u043e\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430<\/a><\/li>\n<li><a href=\"#perebor-elementov-mnozhestva\">\u041f\u0435\u0440\u0435\u0431\u043e\u0440 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#otnosheniya-mezhdu-mnozhestvami\">\u041e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430\u043c\u0438<\/a><br \/> \n<ul>\n<li><a href=\"#ravnye-mnozhestva\">\u0420\u0430\u0432\u043d\u044b\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430<\/a><\/li>\n<li><a href=\"#neperesekayuschiesya-mnozhestva\">\u041d\u0435\u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430<\/a><\/li>\n<li><a href=\"#podmnozhestvo-i-nadmnozhestvo\">\u041f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0438 \u043d\u0430\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#operacii-nad-mnozhestvami\">\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0430\u0434 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430\u043c\u0438<\/a><br \/> \n<ul>\n<li><a href=\"#obedinenie-mnozhestv\">\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/a><\/li>\n<li><a href=\"#dobavlenie-elementov-v-mnozhestvo\">\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e<\/a><\/li>\n<li><a href=\"#peresechenie-mnozhestv\">\u041f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/a><\/li>\n<li><a href=\"#raznost-mnozhestv\">\u0420\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/a><\/li>\n<li><a href=\"#udalenie-elementov-iz-mnozhestva\">\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u0437 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430<\/a><\/li>\n<li><a href=\"#simmetricheskaya-raznost-mnozhestv\">\u0421\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#zaklyuchenie\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/a><\/li>\n<li><a href=\"#poleznye-ssylki\">\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438<\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<h2 id=\"mnozhestvo\">\u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e<\/h2>\n<p>  <\/p>\n<p><a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9C%D0%BD%D0%BE%D0%B6%D0%B5%D1%81%D1%82%D0%B2%D0%BE\">\u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e<\/a> \u2013 \u044d\u0442\u043e \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u044f\u0432\u043b\u044f\u044e\u0449\u0438\u0439\u0441\u044f \u043d\u0430\u0431\u043e\u0440\u043e\u043c, \u0441\u043e\u0432\u043e\u043a\u0443\u043f\u043d\u043e\u0441\u0442\u044c\u044e, \u0441\u043e\u0431\u0440\u0430\u043d\u0438\u0435\u043c \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f <em>\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438<\/em> \u044d\u0442\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430. \u0418\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438:<\/p>\n<p>  <\/p>\n<blockquote><p>\u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u2013 \u044d\u0442\u043e \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u043d\u0435\u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u0430\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432.<\/p><\/blockquote>\n<p>\u0427\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 <em>\u043d\u0435\u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u0430\u044f<\/em>? \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0434\u0432\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u044b, \u0435\u0441\u043b\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b.<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/cg\/u8\/jr\/cgu8jrfauyxljf1lisvlpygmrfa.png\"\/><\/p>\n<p>  <\/p>\n<p>\u042d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c <em>\u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438<\/em>, \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435, \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u044d\u0442\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e.<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/xz\/sk\/wd\/xzskwdkkknnkv05hwh80y4dg_aq.png\"\/><\/p>\n<p>  <\/p>\n<p>\u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0435 \u0438\u0437 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f <em>\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c\u0438<\/em>, \u0430 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u2013 <em>\u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c\u0438<\/em>. \u041a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u043a\u0430\u043a \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0437 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f, \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435\u043c \u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u0422\u0430\u043a \u043a\u0430\u043a \u0442\u0435\u043c\u043e\u0439 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u0432 Python, \u0442\u043e \u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0430 <em>\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0445<\/em> \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430\u0445.<\/p>\n<p>  <\/p>\n<h2 id=\"mnozhestva-v-python\">\u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0432 Python<\/h2>\n<p>  <\/p>\n<p>\u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432 Python \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438. \u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u2013 \u044d\u0442\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435\u043c \u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0444\u0438\u0433\u0443\u0440\u043d\u044b\u0445 \u0441\u043a\u043e\u0431\u043a\u0430\u0445:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">fruits = {&quot;banana&quot;, &quot;apple&quot;, &quot;orange&quot;}<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043d\u0435\u043b\u044c\u0437\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0443\u0441\u0442\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d \u043f\u0443\u0441\u0442\u043e\u0439 \u0441\u043b\u043e\u0432\u0430\u0440\u044c:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">wrong_empty_set = {} print(type(wrong_empty_set))  # \u0412\u044b\u0432\u043e\u0434 &lt;class &quot;dict&quot;&gt;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0443\u0441\u0442\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043d\u0443\u0436\u043d\u043e \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>set()<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">correct_empty_set = set() print(type(correct_empty_set))  # \u0412\u044b\u0432\u043e\u0434 &lt;class &quot;set&quot;&gt;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432 <code>set()<\/code> \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u043e\u0431\u044a\u0435\u043a\u0442, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u0442\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f (<a href=\"https:\/\/docs.python.org\/3\/glossary.html#term-iterable\">Iterable<\/a>):<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">color_list = [&quot;red&quot;, &quot;green&quot;, &quot;green&quot;, &quot;blue&quot;, &quot;purple&quot;, &quot;purple&quot;] color_set = set(color_list) print(color_set)  # \u0412\u044b\u0432\u043e\u0434 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u043c): {&quot;red&quot;, &quot;purple&quot;, &quot;blue&quot;, &quot;green&quot;}<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0449\u0451 \u043e\u0434\u043d\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u2013 \u044d\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <em>set comprehension<\/em>. \u042d\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u044f\u0437\u044b\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0438\u043d\u043e\u0433\u0434\u0430 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 <em>\u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0435\u0439 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430<\/em> \u043f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u0441 <em>list comprehension<\/em> (<a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A1%D0%BF%D0%B8%D1%81%D0%BA%D0%BE%D0%B2%D0%BE%D0%B5_%D0%B2%D0%BA%D0%BB%D1%8E%D1%87%D0%B5%D0%BD%D0%B8%D0%B5\">\u0421\u043f\u0438\u0441\u043a\u043e\u0432\u043e\u0435 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/a>).<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">numbers = [1, 2, 2, 2, 3, 3, 4, 4, 5, 6]  # \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u0441\u043e \u0441\u043f\u0438\u0441\u043a\u043e\u0432\u044b\u043c\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f\u043c\u0438 - \u044d\u0442\u043e # \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0438\u0433\u0443\u0440\u043d\u044b\u0445 \u0441\u043a\u043e\u0431\u043e\u043a \u0432\u043c\u0435\u0441\u0442\u043e \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u044b\u0445 even_numbers = {     number for number in numbers     if number % 2 == 0 } print(even_numbers)  # \u0412\u044b\u0432\u043e\u0434 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u043c): {2, 4, 6}<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"heshiruemye-obekty\">\u0425\u0435\u0448\u0438\u0440\u0443\u0435\u043c\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b<\/h3>\n<p>  <\/p>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 (\u043a\u0430\u043a \u0438 \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439) \u0432 Python \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u0445\u0435\u0448\u0438\u0440\u0443\u0435\u043c\u044b\u0435 (<a href=\"https:\/\/docs.python.org\/3\/glossary.html#term-hashable\">Hashable<\/a>) \u043e\u0431\u044a\u0435\u043a\u0442\u044b. \u042d\u0442\u043e \u043e\u0431\u0443\u0441\u043b\u043e\u0432\u043b\u0435\u043d\u043e \u0442\u0435\u043c \u0444\u0430\u043a\u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044f\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <em>set<\/em> \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A5%D0%B5%D1%88-%D1%82%D0%B0%D0%B1%D0%BB%D0%B8%D1%86%D0%B0\">\u0445\u0435\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445<\/a>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043f\u0438\u0441\u043a\u0438 \u0438 \u0441\u043b\u043e\u0432\u0430\u0440\u0438 \u2013 \u044d\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0432 Python (<em>int<\/em>, <em>float<\/em>, <em>str<\/em>, <em>bool<\/em>, \u0438 \u0442.\u0434.) \u2013 \u0445\u0435\u0448\u0438\u0440\u0443\u0435\u043c\u044b\u0435. \u041d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <em>tuple<\/em>, \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0445\u0435\u0448\u0438\u0440\u0443\u0435\u043c\u044b\u043c\u0438, \u0435\u0441\u043b\u0438 \u0445\u0435\u0448\u0438\u0440\u0443\u0435\u043c\u044b \u0432\u0441\u0435 \u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># \u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0440\u0442\u0435\u0436\u0435\u0439 (tuple) records = {     (&quot;\u041c\u043e\u0441\u043a\u0432\u0430&quot;, 17_200_000),      (&quot;\u0421\u0430\u043d\u043a\u0442-\u041f\u0435\u0442\u0435\u0440\u0431\u0443\u0440\u0433&quot;, 5_400_000),      (&quot;\u041d\u043e\u0432\u043e\u0441\u0438\u0431\u0438\u0440\u0441\u043a&quot;, 1_600_000),     (&quot;\u041c\u043e\u0441\u043a\u0432\u0430&quot;, 17_200_000), }  for city, population in records:     print(city)  # \u0412\u044b\u0432\u043e\u0434 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u043c): \u041c\u043e\u0441\u043a\u0432\u0430 \u041d\u043e\u0432\u043e\u0441\u0438\u0431\u0438\u0440\u0441\u043a \u0421\u0430\u043d\u043a\u0442-\u041f\u0435\u0442\u0435\u0440\u0431\u0443\u0440\u0433<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0431\u044a\u0435\u043a\u0442\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0445\u0435\u0448\u0438\u0440\u0443\u0435\u043c\u044b\u043c\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u041d\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0441\u043c\u044b\u0441\u043b\u0430 \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0432 \u044d\u0442\u043e\u043c \u043c\u0430\u043b\u043e \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0442\u0430\u043a\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u0438\u0445 \u0430\u0434\u0440\u0435\u0441\u0443 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u0442.\u0435. \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0434\u0432\u0430 &quot;\u0440\u0430\u0432\u043d\u044b\u0445&quot; \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">class City:     def __init__(self, name: str):         self.name = name      def __repr__(self) -&gt; str:         &quot;&quot;&quot; \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043c\u0435\u0442\u043e\u0434 __repr__ \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432         &quot;&quot;&quot;         return f'City(&quot;{self.name}&quot;)'  print(City(&quot;Moscow&quot;) == City(&quot;Moscow&quot;))  # \u0412\u044b\u0432\u043e\u0434: False  cities = {City(&quot;Moscow&quot;), City(&quot;Moscow&quot;)} print(cities)  # \u0412\u044b\u0432\u043e\u0434 {City(&quot;Moscow&quot;), City(&quot;Moscow&quot;)}<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u043c\u044b \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c, \u0447\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u044b <code>City(&quot;Moscow&quot;)<\/code> \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0440\u0430\u0432\u043d\u044b\u043c\u0438, \u0438 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435 <code>cities<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043e\u0434\u0438\u043d \u043e\u0431\u044a\u0435\u043a\u0442.<br \/>  \u042d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f, \u0435\u0441\u043b\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0443 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430 \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430 <code>City<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">class City:     def __init__(self, name: str):         # \u0410\u0442\u0440\u0438\u0431\u0443\u0442 name \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f, \u043f\u043e\u043a\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442         # \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u043f\u043e\u043c\u0435\u0442\u0438\u043c \u044d\u0442\u043e\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043a\u0430\u043a \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439         self._name = name      def __hash__(self) -&gt; int:         &quot;&quot;&quot; \u0425\u0435\u0448 \u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u0430         &quot;&quot;&quot;         return hash((self._name, self.__class__))      def __eq__(self, other) -&gt; bool:         &quot;&quot;&quot; \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0443 \u0440\u0430\u0432\u0435\u043d\u0442\u0441\u0432\u0430 (\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 ==)         &quot;&quot;&quot;         if not isinstance(other, self.__class__):             return False         return self._name == other._name      def __repr__(self) -&gt; str:         &quot;&quot;&quot; \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043c\u0435\u0442\u043e\u0434 __repr__ \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432         &quot;&quot;&quot;         return f'City(&quot;{self._name}&quot;)'<\/code><\/pre>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u0445\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0431\u0435\u0437 \u044f\u0432\u043d\u044b\u0445 \u0438 \u043d\u0435\u044f\u0432\u043d\u044b\u0445 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043e\u0448\u0438\u0431\u043e\u043a, \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0425\u0435\u0448 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f, \u043f\u043e\u043a\u0430 \u044d\u0442\u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442<\/li>\n<li>\u0420\u0430\u0432\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439 \u0445\u0435\u0448<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"python\">moscow = City(&quot;Moscow&quot;) moscow_again = City(&quot;Moscow&quot;)  print(moscow == moscow_again and hash(moscow) == hash(moscow_again)) # \u0412\u044b\u0432\u043e\u0434: True  # \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0433\u043e\u0440\u043e\u0434\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0438 \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e cities = {City(&quot;Moscow&quot;), City(&quot;Kazan&quot;), City(&quot;Moscow&quot;)} print(cities)  # \u0412\u044b\u0432\u043e\u0434 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u043c): {City(&quot;Kazan&quot;), City(&quot;Moscow&quot;)}<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"svoystva-mnozhestv\">\u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/h2>\n<p>  <\/p>\n<p>\u0422\u0438\u043f <code>set<\/code> \u0432 Python \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u0442\u0438\u043f\u043e\u043c <code>Collection<\/code> (<a href=\"https:\/\/docs.python.org\/3\/library\/collections.abc.html#module-collections.abc\">\u043f\u0440\u043e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438<\/a>), \u0438\u0437 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0444\u0430\u043a\u0442\u0430 \u0435\u0441\u0442\u044c \u0442\u0440\u0438 \u0432\u0430\u0436\u043d\u044b\u0445 \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443<\/li>\n<li>\u041c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435<\/li>\n<li>\u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f iterable-\u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438<\/li>\n<\/ul>\n<p>  <\/p>\n<h3 id=\"prinadlezhnost-mnozhestvu\">\u041f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443<\/h3>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u043b\u0438 \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u043e\u0431\u044a\u0435\u043a\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443 \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>in<\/code>. \u042d\u0442\u043e \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432. \u0422\u0430\u043a\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u0441\u0440\u0435\u0434\u043d\u0435\u043c \u0437\u0430 <code>O(1)<\/code> \u0441 \u0442\u0435\u043c\u0438 \u0436\u0435 \u043e\u0433\u043e\u0432\u043e\u0440\u043a\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0434\u043b\u044f <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A5%D0%B5%D1%88-%D1%82%D0%B0%D0%B1%D0%BB%D0%B8%D1%86%D0%B0#%D0%A1%D0%B2%D0%BE%D0%B9%D1%81%D1%82%D0%B2%D0%B0_%D1%85%D0%B5%D1%88-%D1%82%D0%B0%D0%B1%D0%BB%D0%B8%D1%86%D1%8B\">\u0445\u0435\u0448-\u0442\u0430\u0431\u043b\u0438\u0446<\/a>.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">tremendously_huge_set = {&quot;red&quot;, &quot;green&quot;, &quot;blue&quot;}  if &quot;green&quot; in tremendously_huge_set:     print(&quot;Green is there!&quot;) else:     print(&quot;Unfortunately, there is no green...&quot;)  # \u0412\u044b\u0432\u043e\u0434: Green is there!  if &quot;purple&quot; in tremendously_huge_set:     print(&quot;Purple is there!&quot;) else:     print(&quot;Unfortunately, there is no purple...&quot;)  # \u0412\u044b\u0432\u043e\u0434: Unfortunately, there is no purple...<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"moschnost-mnozhestva\">\u041c\u043e\u0449\u043d\u043e\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430<\/h3>\n<p>  <\/p>\n<p><em>\u041c\u043e\u0449\u043d\u043e\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430<\/em> \u2013 \u044d\u0442\u043e \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u043b\u044f <em>\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0445<\/em> \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435. \u0414\u043b\u044f <em>\u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0445<\/em> \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u0432\u0441\u0451 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9C%D0%BE%D1%89%D0%BD%D0%BE%D1%81%D1%82%D1%8C_%D0%BC%D0%BD%D0%BE%D0%B6%D0%B5%D1%81%D1%82%D0%B2%D0%B0\">\u0441\u043b\u043e\u0436\u043d\u0435\u0435<\/a>.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">even_numbers = {i for i in range(100) if i % 2 == 0}  # \u041c\u043e\u0449\u043d\u043e\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 cardinality = len(even_numbers) print(cardinality)  # \u0412\u044b\u0432\u043e\u0434: 50<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"perebor-elementov-mnozhestva\">\u041f\u0435\u0440\u0435\u0431\u043e\u0440 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430<\/h3>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0443\u0436\u0435 \u0431\u044b\u043b\u043e \u043e\u0442\u043c\u0435\u0447\u0435\u043d\u043e \u0432\u044b\u0448\u0435, \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043b\u044e\u0431\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043c, \u0433\u0434\u0435 \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f <a href=\"https:\/\/docs.python.org\/3\/glossary.html#term-iterable\">iterable-\u043e\u0431\u044a\u0435\u043a\u0442<\/a>.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">colors = {&quot;red&quot;, &quot;green&quot;, &quot;blue&quot;}  # \u042d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0446\u0438\u043a\u043b\u0430 for for color in colors:     print(color)  # \u0412\u044b\u0432\u043e\u0434 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u043c): red green blue  # \u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043c, \u0433\u0434\u0435 \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f iterable-\u043e\u0431\u044a\u0435\u043a\u0442 color_counter = dict.fromkeys(colors, 1) print(color_counter)  # \u0412\u044b\u0432\u043e\u0434 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u043c): {&quot;green&quot;: 1, &quot;red&quot;: 1, &quot;blue&quot;: 1}<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"otnosheniya-mezhdu-mnozhestvami\">\u041e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430\u043c\u0438<\/h2>\n<p>  <\/p>\n<p>\u041c\u0435\u0436\u0434\u0443 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430\u043c\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0438\u0434\u043e\u0432 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0439, \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0441\u0432\u044f\u0437\u0435\u0439. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430\u043c\u0438 \u0432 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435.<\/p>\n<p>  <\/p>\n<h3 id=\"ravnye-mnozhestva\">\u0420\u0430\u0432\u043d\u044b\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430<\/h3>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/qx\/d7\/pv\/qxd7pv9bmwiq6bl1ndsy42m4dvg.png\"\/><\/p>\n<p>  <\/p>\n<p>\u0422\u0443\u0442 \u0432\u0441\u0451 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u2013 \u0434\u0432\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f <em>\u0440\u0430\u0432\u043d\u044b\u043c\u0438<\/em>, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u0442 \u0438\u0437 \u043e\u0434\u043d\u0438\u0445 \u0438 \u0442\u0435\u0445 \u0436\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u041a\u0430\u043a \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0437 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430, \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u044d\u0442\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0435 \u0432\u0430\u0436\u0435\u043d.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">my_fruits = {&quot;banana&quot;, &quot;apple&quot;, &quot;orange&quot;, &quot;orange&quot;} your_fruits = {&quot;apple&quot;, &quot;apple&quot;, &quot;banana&quot;, &quot;orange&quot;, &quot;orange&quot;} print(my_fruits == your_fruits)  # \u0412\u044b\u0432\u043e\u0434: True<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"neperesekayuschiesya-mnozhestva\">\u041d\u0435\u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430<\/h3>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/h3\/wh\/bc\/h3whbckh3ow_yf-k11rye9iific.png\"\/><\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0434\u0432\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043d\u0435 \u0438\u043c\u0435\u044e\u0442 \u043e\u0431\u0449\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0442\u043e \u0433\u043e\u0432\u043e\u0440\u044f\u0442, \u0447\u0442\u043e \u044d\u0442\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 <em>\u043d\u0435 \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0442\u0441\u044f<\/em>. \u0418\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, <a href=\"#\u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435-\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\">\u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435<\/a> \u044d\u0442\u0438\u0445 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0443\u0441\u0442\u044b\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">even_numbers = {i for i in range(10) if i % 2 == 0} odd_numbers = {i for i in range(10) if i % 2 == 1}  # \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0447\u0451\u0442\u043d\u044b\u0445 \u0438 \u043d\u0435\u0447\u0451\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u043d\u0435 \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0442\u0441\u044f if even_numbers.isdisjoint(odd_numbers):     print(&quot;\u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043d\u0435 \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0442\u0441\u044f!&quot;)  # \u0412\u044b\u0432\u043e\u0434: \u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043d\u0435 \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0442\u0441\u044f!<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"podmnozhestvo-i-nadmnozhestvo\">\u041f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0438 \u043d\u0430\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e<\/h3>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/i3\/qg\/6c\/i3qg6c-r5pngljnfc3jnpgueouo.png\"\/><\/p>\n<p>  <\/p>\n<p><em>\u041f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e<\/em> \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 <em>S<\/em> \u2013 \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0430\u043a\u0436\u0435 \u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 <em>S<\/em>. \u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e <em>S<\/em> \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <em>\u043d\u0430\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c<\/em> \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># \u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0447\u0438\u0441\u0435\u043b \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438 \u043c\u0435\u043d\u044c\u0448\u0438\u0445 100 fibonacci_numbers = {0, 1, 2, 3, 34, 5, 8, 13, 21, 55, 89}  # \u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u043c\u0435\u043d\u044c\u0448\u0438\u0445 100 natural_numbers = set(range(100))  # \u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0447\u0438\u0441\u0435\u043b \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430  # \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b if fibonacci_numbers.issubset(natural_numbers):     print(&quot;\u041f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e!&quot;)  # \u0412\u044b\u0432\u043e\u0434: \u041f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e!  # \u0412 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f # \u043d\u0430\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0447\u0438\u0441\u0435\u043b \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438 if natural_numbers.issuperset(fibonacci_numbers):     print(&quot;\u041d\u0430\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e!&quot;)  # \u0412\u044b\u0432\u043e\u0434: \u041d\u0430\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e!<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0443\u0441\u0442\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u043b\u044e\u0431\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">empty = set()  # \u041c\u0435\u0442\u043e\u0434\u044b issubset \u0438 issuperset \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0439 iterable-\u043e\u0431\u044a\u0435\u043a\u0442 print(     empty.issubset(range(100))     and empty.issubset([&quot;red&quot;, &quot;green&quot;, &quot;blue&quot;])     and empty.issubset(set()) )  # \u0412\u044b\u0432\u043e\u0434: True<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0430\u043c\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <em>\u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c<\/em> \u0441\u0430\u043c\u043e\u0433\u043e \u0441\u0435\u0431\u044f.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">natural_numbers = set(range(100))  if natural_numbers.issubset(natural_numbers):     print(&quot;\u041f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e!&quot;)  # \u0412\u044b\u0432\u043e\u0434: \u041f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e!<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"operacii-nad-mnozhestvami\">\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0430\u0434 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430\u043c\u0438<\/h2>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u043e\u043f\u0440\u0435\u0434\u044f\u043b\u044f\u0435\u043c\u044b\u0435 \u043d\u0430\u0434 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430\u043c\u0438.<\/p>\n<p>  <\/p>\n<h3 id=\"obedinenie-mnozhestv\">\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/h3>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/xs\/gb\/bf\/xsgbbfac8rlncrgym2_8bhzi5ym.png\"\/><\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9E%D0%B1%D1%8A%D0%B5%D0%B4%D0%B8%D0%BD%D0%B5%D0%BD%D0%B8%D0%B5_%D0%BC%D0%BD%D0%BE%D0%B6%D0%B5%D1%81%D1%82%D0%B2\">\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/a> \u2013 \u044d\u0442\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432. \u0412 Python \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0438\u0445 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">my_fruits = {&quot;apple&quot;, &quot;orange&quot;} your_fruits = {&quot;orange&quot;, &quot;banana&quot;, &quot;pear&quot;}  # \u0414\u043b\u044f \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 `|`, # \u043e\u0431\u0430 \u043e\u043f\u0435\u0440\u0430\u043d\u0434\u0430 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0442\u0438\u043f\u0430 set our_fruits = my_fruits | your_fruits print(our_fruits)  # \u0412\u044b\u0432\u043e\u0434 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u043c): {&quot;apple&quot;, &quot;banana&quot;, &quot;orange&quot;, &quot;pear&quot;}  # \u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u043d\u0442\u043e\u0434 union. # \u041e\u0442\u043b\u0438\u0447\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434 union \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e # \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 set, \u0430 \u043b\u044e\u0431\u043e\u0439 iterable-\u043e\u0431\u044a\u0435\u043a\u0442 you_fruit_list: list = list(your_fruits) our_fruits: set = my_fruits.union(you_fruit_list) print(our_fruits)  # \u0412\u044b\u0432\u043e\u0434 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u043c): {&quot;apple&quot;, &quot;banana&quot;, &quot;orange&quot;, &quot;pear&quot;}<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"dobavlenie-elementov-v-mnozhestvo\">\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e<\/h4>\n<p>  <\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u0437\u0430 \u0442\u0435\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c, \u0447\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0430 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442. \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0437\u0430 <code>O(1)<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">colors = {&quot;red&quot;, &quot;green&quot;, &quot;blue&quot;}  # \u041c\u0435\u0442\u043e\u0434 add \u0434\u043e\u0431\u0430\u043b\u044f\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e colors.add(&quot;purple&quot;) # \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435, \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 # \u044d\u0442\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e colors.add(&quot;red&quot;) print(colors)  # \u0412\u044b\u0432\u043e\u0434 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u043c): {&quot;red&quot;, &quot;green&quot;, &quot;blue&quot;, &quot;purple&quot;}  # \u041c\u0435\u0442\u043e\u0434 update \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 iterable-\u043e\u0431\u044a\u0435\u043a\u0442 (\u0441\u043f\u0438\u0441\u043e\u043a, \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0438 \u0442.\u043f.) # \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e numbers = {1, 2, 3} numbers.update(i**2 for i in [1, 2, 3]) print(numbers)  # \u0412\u044b\u0432\u043e\u0434 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u043c): {1, 2, 3, 4, 9}<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"peresechenie-mnozhestv\">\u041f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/h3>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/gz\/6z\/t8\/gz6zt81ypvoklxdte5axkyjv6xu.png\"\/><\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9F%D0%B5%D1%80%D0%B5%D1%81%D0%B5%D1%87%D0%B5%D0%BD%D0%B8%D0%B5_%D0%BC%D0%BD%D0%BE%D0%B6%D0%B5%D1%81%D1%82%D0%B2\">\u041f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/a> \u2013 \u044d\u0442\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430\u043c \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">def is_prime(number: int) -&gt; bool:     &quot;&quot;&quot; \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 True, \u0435\u0441\u043b\u0438 number - \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0447\u0438\u0441\u043b\u043e     &quot;&quot;&quot;     assert number &gt; 1     return all(number % i for i in range(2, int(number**0.5) + 1))  def is_fibonacci(number: int) -&gt; bool:     &quot;&quot;&quot; \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 True, \u0435\u0441\u043b\u0438 number - \u044d\u0442\u043e \u0447\u0438\u0441\u043b\u043e \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438     &quot;&quot;&quot;     assert number &gt; 1     a, b = 0, 1     while a + b &lt; number:         a, b = b, a + b     return a + b == number  # \u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0434\u043e 100 primes = set(filter(is_prime, range(2, 101)))  # \u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0447\u0438\u0441\u0435\u043b \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438 \u0434\u043e 100 fibonacci = set(filter(is_fibonacci, range(2, 101)))  # \u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0434\u043e 100, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f # \u0447\u0438\u0441\u043b\u0430\u043c\u0438 \u0424\u0438\u0431\u043e\u043d\u0430\u0447\u0447\u0438 prime_fibonacci = primes.intersection(fibonacci)  # \u0418\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 `&amp;`, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u0434\u043b\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 prime_fibonacci = fibonacci &amp; primes  print(prime_fibonacci)  # \u0412\u044b\u0432\u043e\u0434 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u043c): {2, 3, 5, 13, 89}<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>&amp;<\/code> \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0430 \u043e\u043f\u0435\u0440\u0430\u043d\u0434\u0430 \u0431\u044b\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0442\u0438\u043f\u0430 <code>set<\/code>. \u041c\u0435\u0442\u043e\u0434 <code>intersection<\/code>, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043b\u044e\u0431\u043e\u0439 <a href=\"https:\/\/docs.python.org\/3\/glossary.html#term-iterable\">iterable-\u043e\u0431\u044a\u0435\u043a\u0442<\/a>. \u0415\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0430 \u043d\u0435 \u0432\u043e\u0437\u0440\u0430\u0449\u0430\u0442\u044c \u043d\u043e\u0432\u043e\u0435, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>intersection_update<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e\u0434\u043e\u0431\u043d\u043e \u043c\u0435\u0442\u043e\u0434\u0443 <code>intersection<\/code>, \u043d\u043e \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442-\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e.<\/p>\n<p>  <\/p>\n<h2 id=\"raznost-mnozhestv\">\u0420\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/h2>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/q9\/xf\/iq\/q9xfiqv0ktvawcvwgzmwnm62rbu.png\"\/><\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A0%D0%B0%D0%B7%D0%BD%D0%BE%D1%81%D1%82%D1%8C_%D0%BC%D0%BD%D0%BE%D0%B6%D0%B5%D1%81%D1%82%D0%B2\">\u0420\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u0434\u0432\u0443\u0445 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/a> \u2013 \u044d\u0442\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0445\u043e\u0434\u044f\u0442 \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430, \u043d\u0435 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">i_know: set = {&quot;Python&quot;, &quot;Go&quot;, &quot;Java&quot;} you_know: dict = {     &quot;Go&quot;: 0.4,      &quot;C++&quot;: 0.6,      &quot;Rust&quot;: 0.2,      &quot;Java&quot;: 0.9 }  # \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 `-` \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e # \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0442\u0438\u043f\u0430 set you_know_but_i_dont = set(you_know) - i_know print(you_know_but_i_dont)  # \u0412\u044b\u0432\u043e\u0434 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u043c): {&quot;Rust&quot;, &quot;C++&quot;}  # \u041c\u0435\u0442\u043e\u0434 difference \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043b\u044e\u0431\u044b\u043c iterable-\u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c, # \u043a\u0430\u043a\u0438\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f dict, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 i_know_but_you_dont = i_know.difference(you_know) print(i_know_but_you_dont)  # \u0412\u044b\u0432\u043e\u0434: {&quot;Python&quot;}<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"udalenie-elementov-iz-mnozhestva\">\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u0437 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430<\/h4>\n<p>  <\/p>\n<p>\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0438\u0437 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 <em>\u0440\u0430\u0437\u043d\u043e\u0441\u0442\u0438<\/em>, \u0433\u0434\u0435 \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u2013 \u044d\u0442\u043e \u043e\u0434\u043d\u043e\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043d\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e. \u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u043a\u0430\u043a \u0438 \u0432 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e. \u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0438\u0437 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0438\u043c\u0435\u0435\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c <code>O(1)<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">fruits = {&quot;apple&quot;, &quot;orange&quot;, &quot;banana&quot;}  # \u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0438\u0437 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430. \u0415\u0441\u043b\u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 # \u043d\u0435\u0442 \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435, \u0442\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 fruits.discard(&quot;orange&quot;) fruits.discard(&quot;pineapple&quot;) print(fruits)  # \u0412\u044b\u0432\u043e\u0434 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u043c): {&quot;apple&quot;, &quot;banana&quot;}  # \u041c\u0435\u0442\u043e\u0434 remove \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e discard, \u043d\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, # \u0435\u0441\u043b\u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043d\u0435\u0442 \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435 fruits.remove(&quot;pineapple&quot;)  # KeyError: &quot;pineapple&quot;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0443 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>differen\u0441e_update<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 <a href=\"https:\/\/docs.python.org\/3\/glossary.html#term-iterable\">iterable-\u043e\u0431\u044a\u0435\u043a\u0442<\/a> \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b iterable-\u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043c\u0435\u0442\u043e\u0434\u0443 <code>difference<\/code>, \u043d\u043e \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0430 \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u043e\u0432\u043e\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} even_numbers_under_100 = (i for i in range(1, 101) if i % 2 == 0) numbers.difference_update(even_numbers_under_100) print(numbers)  # \u0412\u044b\u0432\u043e\u0434 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u043c): {1, 3, 5, 7, 9}<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"simmetricheskaya-raznost-mnozhestv\">\u0421\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/h2>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/1x\/fl\/r3\/1xflr3h8f0hcx1rrccynti3_frs.png\"\/><\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A1%D0%B8%D0%BC%D0%BC%D0%B5%D1%82%D1%80%D0%B8%D1%87%D0%B5%D1%81%D0%BA%D0%B0%D1%8F_%D1%80%D0%B0%D0%B7%D0%BD%D0%BE%D1%81%D1%82%D1%8C\">\u0421\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/a> \u2013 \u044d\u0442\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0435\u0435 \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432, \u043d\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u0435 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043e\u0431\u043e\u0438\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430\u043c. \u0422\u0430\u043a\u0436\u0435 \u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043a\u0430\u043a <em>\u0440\u0430\u0437\u043d\u043e\u0441\u0442\u044c<\/em> \u043c\u0435\u0436\u0434\u0443 <em>\u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435\u043c<\/em> \u0438 <em>\u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435\u043c<\/em> \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">non_positive = {-3, -2, -1, 0} non_negative = {0, 1, 2, 3}  # \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 `^` \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f # \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0442\u0438\u043f\u0430 set non_zero = non_positive ^ non_negative print(non_zero)  # \u0412\u044b\u0432\u043e\u0434 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u043c): {-1, -2, -3, 1, 2, 3}<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u044b\u0448\u0435, \u0447\u0438\u0441\u043b\u043e <code>0<\/code> \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u043e\u0431\u043e\u0438\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430\u043c, \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d\u043e \u043d\u0435 \u0432\u0445\u043e\u0434\u0438\u0442 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e. \u0414\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u0438, \u043f\u043e\u043c\u0438\u043c\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>^<\/code>, \u0442\u0430\u043a\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0432\u0430 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u0430 \u2013 <code>symmetric_difference<\/code> \u0438 <code>symmetric_difference_update<\/code>. \u041e\u0431\u0430 \u044d\u0442\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 <a href=\"https:\/\/docs.python.org\/3\/glossary.html#term-iterable\">iterable-\u043e\u0431\u044a\u0435\u043a\u0442<\/a> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430, \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u0436\u0435 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e <code>symmetric_difference<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442-\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a <code>symmetric_difference_update<\/code> \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">non_positive = {-3, -2, -1, 0} non_negative = range(4)  non_zero = non_positive.symmetric_difference(non_negative) print(non_zero)  # \u0412\u044b\u0432\u043e\u0434 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u043c): {-1, -2, -3, 1, 2, 3}  # \u041c\u0435\u0442\u043e\u0434 symmetric_difference_update \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e colors = {&quot;red&quot;, &quot;green&quot;, &quot;blue&quot;} colors.symmetric_difference_update([&quot;green&quot;, &quot;blue&quot;, &quot;yellow&quot;]) print(colors)  # \u0412\u044b\u0432\u043e\u0434 (\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u043c): {&quot;red&quot;, &quot;yellow&quot;}<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"zaklyuchenie\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u042f \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u043c\u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e Python \u0438\u043c\u0435\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430\u043c\u0438. \u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u044d\u0442\u043e \u0447\u0430\u0441\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0434\u0430, \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0435 \u0438 \u043b\u0435\u0433\u0447\u0435 \u0434\u043b\u044f \u0432\u043e\u0441\u043f\u0440\u0438\u044f\u0442\u0438\u044f, \u0430 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u043c. \u042f \u0431\u0443\u0434\u0443 \u0440\u0430\u0434, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u044f \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<h2 id=\"poleznye-ssylki\">\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438<\/h2>\n<p>  <\/p>\n<p><a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9C%D0%BD%D0%BE%D0%B6%D0%B5%D1%81%D1%82%D0%B2%D0%BE\">\u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430<\/a> (\u0421\u0442\u0430\u0442\u044c\u044f \u043d\u0430 \u0412\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u0438)<br \/>  <a href=\"https:\/\/docs.python.org\/3\/library\/stdtypes.html?highlight=set#set-types-set-frozenset\">\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043f\u043e \u0442\u0438\u043f\u0443 set<\/a><br \/>  <a href=\"https:\/\/docs.python.org\/3\/glossary.html#term-iterable\">Iterable-\u043e\u0431\u044a\u0435\u043a\u0442\u044b<\/a> (\u0413\u043b\u043e\u0441\u0441\u0430\u0440\u0438\u0439 Python)<br \/>  <a href=\"https:\/\/docs.python.org\/3\/glossary.html#term-hashable\">Hashable-\u043e\u0431\u044a\u0435\u043a\u0442\u044b<\/a> (\u0413\u043b\u043e\u0441\u0441\u0430\u0440\u0438\u0439 Python)<br \/>  <a href=\"https:\/\/realpython.com\/python-sets\/\">Sets in Python<\/a><br \/>  <a href=\"https:\/\/medium.com\/basecs\/set-theory-the-method-to-database-madness-5ec4b4f05d79\">Set Theory: the Method To Database Madness<\/a><\/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\/516858\/\"> https:\/\/habr.com\/ru\/post\/516858\/<\/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\/516858\/\">\n<h1 id=\"python-i-teoriya-mnozhestv\">Python \u0438 \u0442\u0435\u043e\u0440\u0438\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/h1>\n<p>  <\/p>\n<p>\u0412 Python \u0435\u0441\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430\u043c\u0438 \u2013 \u044d\u0442\u043e <em>set<\/em>. \u041e\u0431 \u044d\u0442\u043e\u043c \u0442\u0438\u043f\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0432\u044b\u0434\u0435\u0440\u0436\u043a\u0435 \u0438\u0437 \u0442\u0435\u043e\u0440\u0438\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u043f\u043e\u0439\u0434\u0451\u0442 \u0440\u0435\u0447\u044c \u0434\u0430\u043b\u0435\u0435. <\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/9h\/tq\/c0\/9htqc0r1cr_tf1jystcwwayzrww.png\"\/><\/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-309089","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/309089","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=309089"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/309089\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=309089"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=309089"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=309089"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}