{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "059b7d10",
   "metadata": {},
   "source": [
    "# 11-13 · append, extend, insert\n",
    "\n",
    "Практика к разделу [«append, extend, insert»](../../site/chapters/glava-11/11-13-append-extend-insert.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9d6ac91e",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Правильно выбрать между append(), extend() и insert()."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ef16337d",
   "metadata": {},
   "source": [
    "## Рабочий пример — ловушка append() vs extend()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9ac26927",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T14:44:36.350385Z",
     "iopub.status.busy": "2026-08-17T14:44:36.350260Z",
     "iopub.status.idle": "2026-08-17T14:44:36.372978Z",
     "shell.execute_reply": "2026-08-17T14:44:36.372469Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, [3, 4]]\n",
      "[1, 2, 3, 4]\n"
     ]
    }
   ],
   "source": [
    "a = [1, 2]\n",
    "a.append([3, 4])\n",
    "print(a)\n",
    "\n",
    "b = [1, 2]\n",
    "b.extend([3, 4])\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0b8f9df2",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Соберите список покупок: начните с `[\"хлеб\", \"молоко\"]`, добавьте `\"яйца\"` одним элементом, добавьте элементы из `[\"сыр\", \"масло\"]`, а затем вставьте `\"вода\"` в самое начало."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d392333e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T14:44:36.374013Z",
     "iopub.status.busy": "2026-08-17T14:44:36.373902Z",
     "iopub.status.idle": "2026-08-17T14:44:36.376241Z",
     "shell.execute_reply": "2026-08-17T14:44:36.375796Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['вода', 'хлеб', 'молоко', 'яйца', 'сыр', 'масло']\n"
     ]
    }
   ],
   "source": [
    "cart = [\"хлеб\", \"молоко\"]\n",
    "cart.append(\"яйца\")\n",
    "cart.extend([\"сыр\", \"масло\"])\n",
    "cart.insert(0, \"вода\")\n",
    "print(cart)"
   ]
  }
 ],
 "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
}
