{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Functions and Collections — Lesson 3\n",
    "## Practice tasks\n",
    "\n",
    "**Topics:** tuples, sets, dicts, `def`, `return`, default parameters, `*args` / `**kwargs`, scope, `lambda`\n",
    "\n",
    "Replace `pass` with your code and run the cell (Shift + Enter)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "## Task 1. Rectangle area\n",
    "\n",
    "Write a function `area(width, height)` that returns the area of a rectangle. Test with `area(5, 3)`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Your code here\n",
    "pass"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "## Task 2. Min, Max, Avg via function\n",
    "\n",
    "Write `summary(numbers)` that takes a list and returns a tuple `(min, max, avg)`. Unpack the result into three variables.\n",
    "\n",
    "```python\n",
    "data = [12, 7, 23, 9, 31, 4, 18]\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = [12, 7, 23, 9, 31, 4, 18]\n",
    "\n",
    "# Your code here\n",
    "pass"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "## Task 3. Unique words\n",
    "\n",
    "Given a string, count the number of unique words using `set` (case-insensitive).\n",
    "\n",
    "```python\n",
    "text = \"Python is great Python is fun and Python is fast\"\n",
    "```\n",
    "\n",
    "Expected: 7."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "text = \"Python is great Python is fun and Python is fast\"\n",
    "\n",
    "# Your code here\n",
    "pass"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "## Task 4. Letter frequency\n",
    "\n",
    "Build a dict `{letter: count}` for a given word, ignoring spaces and case.\n",
    "\n",
    "```python\n",
    "word = \"programming\"\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "word = \"programming\"\n",
    "\n",
    "# Your code here\n",
    "pass"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "## Task 5. Merge dicts\n",
    "\n",
    "Write `merge(d1, d2)` that merges two dicts. If a key exists in both, `d2` wins. Do not use the `|` operator.\n",
    "\n",
    "```python\n",
    "a = {\"x\": 1, \"y\": 2}\n",
    "b = {\"y\": 99, \"z\": 3}\n",
    "# merge(a, b) → {\"x\": 1, \"y\": 99, \"z\": 3}\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Your code here\n",
    "pass"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "## Task 6. Default parameter\n",
    "\n",
    "Write `power(base, exp=2)` that returns `base ** exp`. Verify with `power(5)` and `power(2, 10)`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Your code here\n",
    "pass"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "## Task 7. *args — product\n",
    "\n",
    "Write `product(*nums)` that returns the product of all arguments. With no arguments — return 1.\n",
    "\n",
    "```python\n",
    "product(2, 3, 4)   # → 24\n",
    "product()          # → 1\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Your code here\n",
    "pass"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "## Task 8. **kwargs — URL builder\n",
    "\n",
    "Write `build_url(base, **params)` that returns a string `base?key1=val1&key2=val2`.\n",
    "\n",
    "```python\n",
    "build_url(\"https://api.example.com\", lang=\"en\", page=2)\n",
    "# → \"https://api.example.com?lang=en&page=2\"\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Your code here\n",
    "pass"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "## Task 9. Sorting via lambda\n",
    "\n",
    "Given a list of product dicts, sort by price descending using `sorted` and `lambda`.\n",
    "\n",
    "```python\n",
    "products = [\n",
    "    {\"name\": \"book\", \"price\": 12},\n",
    "    {\"name\": \"phone\", \"price\": 599},\n",
    "    {\"name\": \"pen\", \"price\": 3},\n",
    "    {\"name\": \"laptop\", \"price\": 1200},\n",
    "]\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "products = [\n",
    "    {\"name\": \"book\", \"price\": 12},\n",
    "    {\"name\": \"phone\", \"price\": 599},\n",
    "    {\"name\": \"pen\", \"price\": 3},\n",
    "    {\"name\": \"laptop\", \"price\": 1200},\n",
    "]\n",
    "\n",
    "# Your code here\n",
    "pass"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "## Task 10. Group words by length\n",
    "\n",
    "Write `group_by_len(words)` that returns `{length: [words of that length]}`.\n",
    "\n",
    "```python\n",
    "words = [\"sun\", \"moon\", \"sky\", \"star\", \"cloud\", \"rain\", \"snow\"]\n",
    "# → {3: [\"sun\", \"sky\"], 4: [\"moon\", \"star\", \"rain\", \"snow\"], 5: [\"cloud\"]}\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "words = [\"sun\", \"moon\", \"sky\", \"star\", \"cloud\", \"rain\", \"snow\"]\n",
    "\n",
    "# Your code here\n",
    "pass"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
