{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "33473fc5",
   "metadata": {},
   "source": [
    "# 18-10 · Item ID: что возвращает create_*\n",
    "\n",
    "Практика к разделу [«Item ID: что возвращает create_*»](../../site/chapters/glava-18/18-10-item-id.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "522de897",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Хранить фигуры по item_id — как по ключу словаря, а не как по индексу списка."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "610c5518",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b85af8cf",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T00:51:32.939323Z",
     "iopub.status.busy": "2026-09-03T00:51:32.939196Z",
     "iopub.status.idle": "2026-09-03T00:51:32.962695Z",
     "shell.execute_reply": "2026-09-03T00:51:32.962115Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{3: 'rectangle', 7: 'oval'}\n"
     ]
    }
   ],
   "source": [
    "shapes_by_id = {}\n",
    "\n",
    "\n",
    "def zaregistrirovat_figuru(shapes_by_id, item_id, kind):\n",
    "    shapes_by_id[item_id] = kind\n",
    "    return shapes_by_id\n",
    "\n",
    "\n",
    "zaregistrirovat_figuru(shapes_by_id, 3, \"rectangle\")\n",
    "zaregistrirovat_figuru(shapes_by_id, 7, \"oval\")\n",
    "print(shapes_by_id)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2616921c",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6ee5d42f",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T00:51:32.963945Z",
     "iopub.status.busy": "2026-09-03T00:51:32.963804Z",
     "iopub.status.idle": "2026-09-03T00:51:32.966591Z",
     "shell.execute_reply": "2026-09-03T00:51:32.966058Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "item_id используется как ключ словаря, а не как индекс списка.\n"
     ]
    }
   ],
   "source": [
    "assert shapes_by_id[3] == \"rectangle\"\n",
    "assert shapes_by_id[7] == \"oval\"\n",
    "assert 5 not in shapes_by_id\n",
    "print(\"item_id используется как ключ словаря, а не как индекс списка.\")"
   ]
  }
 ],
 "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
}
