{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "1e5818fc",
   "metadata": {},
   "source": [
    "# 18-11 · Теги: группируем и выбираем элементы\n",
    "\n",
    "Практика к разделу [«Теги: группируем и выбираем элементы»](../../site/chapters/glava-18/18-11-tegi.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6bfa9628",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Смоделировать группировку элементов Canvas по тегам — без Tkinter."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4f1eeb27",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "109038f3",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T00:51:35.337741Z",
     "iopub.status.busy": "2026-09-03T00:51:35.337585Z",
     "iopub.status.idle": "2026-09-03T00:51:35.363139Z",
     "shell.execute_reply": "2026-09-03T00:51:35.362507Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'shape': [12, 13], 'preview': [15]}\n"
     ]
    }
   ],
   "source": [
    "tegi = {}\n",
    "\n",
    "\n",
    "def dobavit_v_teg(tegi, tag, item_id):\n",
    "    tegi.setdefault(tag, []).append(item_id)\n",
    "    return tegi\n",
    "\n",
    "\n",
    "dobavit_v_teg(tegi, \"shape\", 12)\n",
    "dobavit_v_teg(tegi, \"shape\", 13)\n",
    "dobavit_v_teg(tegi, \"preview\", 15)\n",
    "print(tegi)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "91d542d8",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8bf1b190",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T00:51:35.364358Z",
     "iopub.status.busy": "2026-09-03T00:51:35.364215Z",
     "iopub.status.idle": "2026-09-03T00:51:35.366993Z",
     "shell.execute_reply": "2026-09-03T00:51:35.366439Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Один тег — сразу несколько элементов.\n"
     ]
    }
   ],
   "source": [
    "assert tegi[\"shape\"] == [12, 13]\n",
    "assert tegi[\"preview\"] == [15]\n",
    "assert len(tegi[\"shape\"]) == 2\n",
    "print(\"Один тег — сразу несколько элементов.\")"
   ]
  }
 ],
 "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
}
