{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c43d7677",
   "metadata": {},
   "source": [
    "# 11-07 · Множества\n",
    "\n",
    "Практика к разделу [«Множества»](../../site/chapters/glava-11/11-07-mnozhestva.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9c2b4c35",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Освоить set и операции над множествами."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a8c2d3dc",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "04342a16",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:55:46.429438Z",
     "iopub.status.busy": "2026-08-14T20:55:46.429282Z",
     "iopub.status.idle": "2026-08-14T20:55:46.449643Z",
     "shell.execute_reply": "2026-08-14T20:55:46.448979Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1, 2, 3}\n"
     ]
    }
   ],
   "source": [
    "chisla = {1, 2, 2, 3, 3, 3}\n",
    "print(chisla)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "92dfbeab",
   "metadata": {},
   "source": [
    "## Эксперимент 1 — убираем повторы из списка"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "bb10c623",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:55:46.451077Z",
     "iopub.status.busy": "2026-08-14T20:55:46.450884Z",
     "iopub.status.idle": "2026-08-14T20:55:46.454317Z",
     "shell.execute_reply": "2026-08-14T20:55:46.453738Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1, 2, 3, 4}\n",
      "4 уникальных значений\n"
     ]
    }
   ],
   "source": [
    "spisok_s_povtorami = [1, 2, 2, 3, 1, 4, 4, 4]\n",
    "unikalnye = set(spisok_s_povtorami)\n",
    "print(unikalnye)\n",
    "print(len(unikalnye), \"уникальных значений\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6fb327ce",
   "metadata": {},
   "source": [
    "## Эксперимент 2 — операции над множествами"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "07164b3b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:55:46.455425Z",
     "iopub.status.busy": "2026-08-14T20:55:46.455286Z",
     "iopub.status.idle": "2026-08-14T20:55:46.458655Z",
     "shell.execute_reply": "2026-08-14T20:55:46.457916Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Объединение: {1, 2, 3, 4}\n",
      "Пересечение: {2, 3}\n",
      "Разность a-b: {1}\n",
      "Разность b-a: {4}\n"
     ]
    }
   ],
   "source": [
    "a = {1, 2, 3}\n",
    "b = {2, 3, 4}\n",
    "print(\"Объединение:\", a | b)\n",
    "print(\"Пересечение:\", a & b)\n",
    "print(\"Разность a-b:\", a - b)\n",
    "print(\"Разность b-a:\", b - a)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a43e3379",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Найдите общих участников двух списков (пересечение множеств)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a0c84c06",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:55:46.459826Z",
     "iopub.status.busy": "2026-08-14T20:55:46.459706Z",
     "iopub.status.idle": "2026-08-14T20:55:46.462322Z",
     "shell.execute_reply": "2026-08-14T20:55:46.461831Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'Вера', 'Гриша'}\n"
     ]
    }
   ],
   "source": [
    "group_a = [\"Аня\", \"Боря\", \"Вера\", \"Гриша\"]\n",
    "group_b = [\"Вера\", \"Гриша\", \"Даша\"]\n",
    "common = set(group_a) & set(group_b)\n",
    "print(common)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Cartesian Python 3.14",
   "language": "python",
   "name": "cartesian-python314"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.14.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
