{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Topic 4: Practice problems (lists and tuples)\n",
    "\n",
    "Asiman Data School, Module 1: Foundations of Python Programming. Week 2, Thursday.\n",
    "\n",
    "Fifteen problems in three levels, on the same ideas and at the same level as the lesson notebook.\n",
    "\n",
    "How to work\n",
    "\n",
    "- Write your code in the cell under each problem. The lines that are already in the cell read the input for you. Where a problem asks for a function, write it above those lines; until it is written, the cell stops with a NameError, and that is expected.\n",
    "- When the cell runs, a small box appears. Type the value there and press Enter. Several numbers on one line are typed with spaces between them.\n",
    "- Run your code with every row of the examples table and compare the output. Print exactly what the problem asks for.\n",
    "- A hint and one possible solution are under each problem. Open them only after you have tried.\n",
    "\n",
    "Tip: For every problem, first decide whether you need a list or a tuple, then whether you must change every item (`map` or a loop with `append`), choose some items (`filter` or a loop with `if`), or reduce the list to one value (`sum`, `max`, a counter)."
   ],
   "id": "t04p-000"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Easy"
   ],
   "id": "t04p-001"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 1. Product of three numbers\n",
    "\n",
    "Read three whole numbers from one line and print their product.\n",
    "\n",
    "Examples\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `2 3 4` | `24` |\n",
    "| `1 1 1` | `1` |\n",
    "| `5 0 9` | `0` |\n",
    "| `-2 3 4` | `-24` |\n",
    "| `10 10 10` | `1000` |"
   ],
   "id": "t04p-002"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "asiman": {
     "typed": [
      "2 3 4"
     ]
    }
   },
   "outputs": [],
   "source": [
    "# Read the three numbers from one line, then print their product"
   ],
   "id": "t04p-003"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "`a, b, c = map(int, input().split())` reads all three. Then multiply them.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "a, b, c = map(int, input().split())\n",
    "print(a * b * c)\n",
    "```\n",
    "\n",
    "**Test cases**\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `2 3 4` | `24` |\n",
    "| `1 1 1` | `1` |\n",
    "| `5 0 9` | `0` |\n",
    "| `-2 3 4` | `-24` |\n",
    "| `10 10 10` | `1000` |\n",
    "\n",
    "</details>"
   ],
   "id": "t04p-004"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 2. First and last\n",
    "\n",
    "Read a list of numbers from one line and print the first and the last item, on one line with a space between them.\n",
    "\n",
    "Examples\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `4 8 15 16` | `4 16` |\n",
    "| `7` | `7 7` |\n",
    "| `1 2` | `1 2` |\n",
    "| `-5 0 5` | `-5 5` |"
   ],
   "id": "t04p-005"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "asiman": {
     "typed": [
      "4 8 15 16"
     ]
    }
   },
   "outputs": [],
   "source": [
    "numbers = list(map(int, input().split()))\n",
    "# Write your code here"
   ],
   "id": "t04p-006"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "The first item is `numbers[0]`, the last is `numbers[-1]`. `print(a, b)` puts a space between two values.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "numbers = list(map(int, input().split()))\n",
    "print(numbers[0], numbers[-1])\n",
    "```\n",
    "\n",
    "**Test cases**\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `4 8 15 16` | `4 16` |\n",
    "| `7` | `7 7` |\n",
    "| `1 2` | `1 2` |\n",
    "| `-5 0 5` | `-5 5` |\n",
    "\n",
    "</details>"
   ],
   "id": "t04p-007"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 3. Four facts about a list\n",
    "\n",
    "Read a list of numbers and print how many items it has, their sum, the smallest and the largest, on one line with spaces between them.\n",
    "\n",
    "Examples\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `10 20 30 40` | `4 100 10 40` |\n",
    "| `5` | `1 5 5 5` |\n",
    "| `3 -1 4 -1 5` | `5 10 -1 5` |\n",
    "| `0 0 0` | `3 0 0 0` |"
   ],
   "id": "t04p-008"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "asiman": {
     "typed": [
      "10 20 30 40"
     ]
    }
   },
   "outputs": [],
   "source": [
    "numbers = list(map(int, input().split()))\n",
    "# Write your code here"
   ],
   "id": "t04p-009"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "Four built-in functions do all the work: `len`, `sum`, `min`, `max`.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "numbers = list(map(int, input().split()))\n",
    "print(len(numbers), sum(numbers), min(numbers), max(numbers))\n",
    "```\n",
    "\n",
    "**Test cases**\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `10 20 30 40` | `4 100 10 40` |\n",
    "| `5` | `1 5 5 5` |\n",
    "| `3 -1 4 -1 5` | `5 10 -1 5` |\n",
    "| `0 0 0` | `3 0 0 0` |\n",
    "\n",
    "</details>"
   ],
   "id": "t04p-010"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 4. Sum of the even numbers\n",
    "\n",
    "Read a list of numbers and print the sum of the even numbers.\n",
    "\n",
    "Examples\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `3 8 5 12 7 10` | `30` |\n",
    "| `1 3 5` | `0` |\n",
    "| `2` | `2` |\n",
    "| `0 -4 9` | `-4` |\n",
    "| `6 6 6` | `18` |"
   ],
   "id": "t04p-011"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "asiman": {
     "typed": [
      "3 8 5 12 7 10"
     ]
    }
   },
   "outputs": [],
   "source": [
    "numbers = list(map(int, input().split()))\n",
    "# Write your code here"
   ],
   "id": "t04p-012"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "An accumulator that starts at 0, a `for` loop over the list, and `if number % 2 == 0` inside it.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "numbers = list(map(int, input().split()))\n",
    "total = 0\n",
    "for number in numbers:\n",
    "    if number % 2 == 0:\n",
    "        total = total + number\n",
    "print(total)\n",
    "```\n",
    "\n",
    "**Test cases**\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `3 8 5 12 7 10` | `30` |\n",
    "| `1 3 5` | `0` |\n",
    "| `2` | `2` |\n",
    "| `0 -4 9` | `-4` |\n",
    "| `6 6 6` | `18` |\n",
    "\n",
    "</details>"
   ],
   "id": "t04p-013"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 5. Count the target\n",
    "\n",
    "Read a list of numbers and a target number (on the second line). Print how many times the target appears in the list.\n",
    "\n",
    "Examples\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `1 2 2 3 2, 2` | `3` |\n",
    "| `5 5 5, 5` | `3` |\n",
    "| `1 2 3, 9` | `0` |\n",
    "| `7, 7` | `1` |\n",
    "| `0 1 0, 0` | `2` |"
   ],
   "id": "t04p-014"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "asiman": {
     "typed": [
      "1 2 2 3 2",
      "2"
     ]
    }
   },
   "outputs": [],
   "source": [
    "numbers = list(map(int, input().split()))\n",
    "target = int(input())\n",
    "# Write your code here"
   ],
   "id": "t04p-015"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "One list method answers this: `count`.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "numbers = list(map(int, input().split()))\n",
    "target = int(input())\n",
    "print(numbers.count(target))\n",
    "```\n",
    "\n",
    "**Test cases**\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `1 2 2 3 2, 2` | `3` |\n",
    "| `5 5 5, 5` | `3` |\n",
    "| `1 2 3, 9` | `0` |\n",
    "| `7, 7` | `1` |\n",
    "| `0 1 0, 0` | `2` |\n",
    "\n",
    "</details>"
   ],
   "id": "t04p-016"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Medium"
   ],
   "id": "t04p-017"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 6. Reverse order\n",
    "\n",
    "Read a list of numbers and print them in reverse order on one line, with spaces between them and without brackets.\n",
    "\n",
    "Examples\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `1 2 3 4 5` | `5 4 3 2 1` |\n",
    "| `7` | `7` |\n",
    "| `10 20` | `20 10` |\n",
    "| `3 3 1` | `1 3 3` |"
   ],
   "id": "t04p-018"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "asiman": {
     "typed": [
      "1 2 3 4 5"
     ]
    }
   },
   "outputs": [],
   "source": [
    "numbers = list(map(int, input().split()))\n",
    "# Write your code here"
   ],
   "id": "t04p-019"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "`numbers[::-1]` is the reversed list. A star prints a list without brackets: `print(*some_list)`.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "numbers = list(map(int, input().split()))\n",
    "print(*numbers[::-1])\n",
    "```\n",
    "\n",
    "**Test cases**\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `1 2 3 4 5` | `5 4 3 2 1` |\n",
    "| `7` | `7` |\n",
    "| `10 20` | `20 10` |\n",
    "| `3 3 1` | `1 3 3` |\n",
    "\n",
    "</details>"
   ],
   "id": "t04p-020"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 7. Double every number\n",
    "\n",
    "Read a list of numbers and print a new list where every number is doubled. Solve it with a loop, then with `map`. Print the list once.\n",
    "\n",
    "Examples\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `1 2 3` | `[2, 4, 6]` |\n",
    "| `0` | `[0]` |\n",
    "| `-4 5` | `[-8, 10]` |\n",
    "| `10 20 30 40` | `[20, 40, 60, 80]` |"
   ],
   "id": "t04p-021"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "asiman": {
     "typed": [
      "1 2 3"
     ]
    }
   },
   "outputs": [],
   "source": [
    "numbers = list(map(int, input().split()))\n",
    "# Write your code here"
   ],
   "id": "t04p-022"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "Loop: start with an empty list and `append(number * 2)`. With `map`: `list(map(lambda n: n * 2, numbers))`.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "numbers = list(map(int, input().split()))\n",
    "\n",
    "# with a loop\n",
    "doubled = []\n",
    "for number in numbers:\n",
    "    doubled.append(number * 2)\n",
    "\n",
    "# with map (the same result)\n",
    "doubled = list(map(lambda n: n * 2, numbers))\n",
    "\n",
    "print(doubled)\n",
    "```\n",
    "\n",
    "**Test cases**\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `1 2 3` | `[2, 4, 6]` |\n",
    "| `0` | `[0]` |\n",
    "| `-4 5` | `[-8, 10]` |\n",
    "| `10 20 30 40` | `[20, 40, 60, 80]` |\n",
    "\n",
    "</details>"
   ],
   "id": "t04p-023"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 8. Longest word\n",
    "\n",
    "Read a list of words from one line and print the longest word and its length, with a space between them. If several words have the same length, print the first of them.\n",
    "\n",
    "Examples\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `python makes data science easier` | `science 7` |\n",
    "| `a bb cc` | `bb 2` |\n",
    "| `hello` | `hello 5` |\n",
    "| `one three five` | `three 5` |"
   ],
   "id": "t04p-024"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "asiman": {
     "typed": [
      "python makes data science easier"
     ]
    }
   },
   "outputs": [],
   "source": [
    "words = input().split()\n",
    "# Write your code here"
   ],
   "id": "t04p-025"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "`max(words, key=len)` gives the longest word (the first one when several are equally long).\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "words = input().split()\n",
    "longest = max(words, key=len)\n",
    "print(longest, len(longest))\n",
    "```\n",
    "\n",
    "**Test cases**\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `python makes data science easier` | `science 7` |\n",
    "| `a bb cc` | `bb 2` |\n",
    "| `hello` | `hello 5` |\n",
    "| `one three five` | `three 5` |\n",
    "\n",
    "</details>"
   ],
   "id": "t04p-026"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 9. Count the numbers above a limit\n",
    "\n",
    "Write a function `count_above(numbers, limit)` that returns how many numbers are greater than `limit`.\n",
    "\n",
    "Examples\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `3 8 5 12 7, 6` | `3` |\n",
    "| `1 2 3, 3` | `0` |\n",
    "| `10 10 10, 9` | `3` |\n",
    "| `5, 5` | `0` |\n",
    "| `-1 -2 0, -2` | `2` |"
   ],
   "id": "t04p-027"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "asiman": {
     "typed": [
      "3 8 5 12 7",
      "6"
     ]
    }
   },
   "outputs": [],
   "source": [
    "# Write your function here\n",
    "\n",
    "\n",
    "numbers = list(map(int, input().split()))\n",
    "limit = int(input())\n",
    "print(count_above(numbers, limit))"
   ],
   "id": "t04p-028"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "The counter pattern inside a function: start at 0, add 1 when `number > limit`, and `return` the counter after the loop.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "def count_above(numbers, limit):\n",
    "    count = 0\n",
    "    for number in numbers:\n",
    "        if number > limit:\n",
    "            count = count + 1\n",
    "    return count\n",
    "\n",
    "numbers = list(map(int, input().split()))\n",
    "limit = int(input())\n",
    "print(count_above(numbers, limit))\n",
    "```\n",
    "\n",
    "**Test cases**\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `3 8 5 12 7, 6` | `3` |\n",
    "| `1 2 3, 3` | `0` |\n",
    "| `10 10 10, 9` | `3` |\n",
    "| `5, 5` | `0` |\n",
    "| `-1 -2 0, -2` | `2` |\n",
    "\n",
    "</details>"
   ],
   "id": "t04p-029"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 10. Is it sorted?\n",
    "\n",
    "Read a list of numbers and print `True` if the list is sorted from smallest to largest, otherwise `False`.\n",
    "\n",
    "Examples\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `1 2 3 4` | `True` |\n",
    "| `1 3 2` | `False` |\n",
    "| `5` | `True` |\n",
    "| `2 2 3` | `True` |\n",
    "| `9 8 7` | `False` |\n",
    "| `1 2 3 3 2` | `False` |"
   ],
   "id": "t04p-030"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "asiman": {
     "typed": [
      "1 2 3 4"
     ]
    }
   },
   "outputs": [],
   "source": [
    "numbers = list(map(int, input().split()))\n",
    "# Write your code here"
   ],
   "id": "t04p-031"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "Compare the list with its sorted version: `numbers == sorted(numbers)`. Or loop over the indexes and compare each item with the next one.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "numbers = list(map(int, input().split()))\n",
    "print(numbers == sorted(numbers))\n",
    "```\n",
    "\n",
    "**Test cases**\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `1 2 3 4` | `True` |\n",
    "| `1 3 2` | `False` |\n",
    "| `5` | `True` |\n",
    "| `2 2 3` | `True` |\n",
    "| `9 8 7` | `False` |\n",
    "| `1 2 3 3 2` | `False` |\n",
    "\n",
    "</details>"
   ],
   "id": "t04p-032"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Medium-Hard"
   ],
   "id": "t04p-033"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 11. Remove the duplicates\n",
    "\n",
    "Read a list of numbers and remove all duplicates, keeping the first appearance of each number. Print the new list.\n",
    "\n",
    "Examples\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `3 5 3 8 5 3 9` | `[3, 5, 8, 9]` |\n",
    "| `1 1 1` | `[1]` |\n",
    "| `4` | `[4]` |\n",
    "| `1 2 3` | `[1, 2, 3]` |\n",
    "| `2 1 2 1` | `[2, 1]` |"
   ],
   "id": "t04p-034"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "asiman": {
     "typed": [
      "3 5 3 8 5 3 9"
     ]
    }
   },
   "outputs": [],
   "source": [
    "numbers = list(map(int, input().split()))\n",
    "# Write your code here"
   ],
   "id": "t04p-035"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "Build a new list: add a number only when it is `not in` the new list yet (solved problem 12).\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "numbers = list(map(int, input().split()))\n",
    "unique = []\n",
    "for number in numbers:\n",
    "    if number not in unique:\n",
    "        unique.append(number)\n",
    "print(unique)\n",
    "```\n",
    "\n",
    "**Test cases**\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `3 5 3 8 5 3 9` | `[3, 5, 8, 9]` |\n",
    "| `1 1 1` | `[1]` |\n",
    "| `4` | `[4]` |\n",
    "| `1 2 3` | `[1, 2, 3]` |\n",
    "| `2 1 2 1` | `[2, 1]` |\n",
    "\n",
    "</details>"
   ],
   "id": "t04p-036"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 12. Second smallest\n",
    "\n",
    "Read a list of numbers and print the second smallest different number. The list always has at least two different numbers. Example: `4 1 7 1 3` gives `3`.\n",
    "\n",
    "Examples\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `4 1 7 1 3` | `3` |\n",
    "| `5 5 6` | `6` |\n",
    "| `10 9` | `10` |\n",
    "| `2 8 2 8 5` | `5` |\n",
    "| `-3 -1 -3` | `-1` |"
   ],
   "id": "t04p-037"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "asiman": {
     "typed": [
      "4 1 7 1 3"
     ]
    }
   },
   "outputs": [],
   "source": [
    "numbers = list(map(int, input().split()))\n",
    "# Write your code here"
   ],
   "id": "t04p-038"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "Find the smallest with `min`. Keep only the numbers that are different from it (`filter`, or a loop with `if`). The smallest of the rest is the answer (solved problem 11 does this for the largest).\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "numbers = list(map(int, input().split()))\n",
    "smallest = min(numbers)\n",
    "others = list(filter(lambda n: n != smallest, numbers))\n",
    "print(min(others))\n",
    "```\n",
    "\n",
    "**Test cases**\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `4 1 7 1 3` | `3` |\n",
    "| `5 5 6` | `6` |\n",
    "| `10 9` | `10` |\n",
    "| `2 8 2 8 5` | `5` |\n",
    "| `-3 -1 -3` | `-1` |\n",
    "\n",
    "</details>"
   ],
   "id": "t04p-039"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 13. Squares of the odd numbers\n",
    "\n",
    "Read a list of numbers and print the sum of the squares of the odd numbers. Use `filter` and `map`.\n",
    "\n",
    "Examples\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `1 2 3 4 5 6` | `35` |\n",
    "| `2 4 6` | `0` |\n",
    "| `7` | `49` |\n",
    "| `-3 2` | `9` |\n",
    "| `1 1 1` | `3` |"
   ],
   "id": "t04p-040"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "asiman": {
     "typed": [
      "1 2 3 4 5 6"
     ]
    }
   },
   "outputs": [],
   "source": [
    "numbers = list(map(int, input().split()))\n",
    "# Write your code here"
   ],
   "id": "t04p-041"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "First choose, then change, then add: `filter` keeps the odd numbers, `map` squares them, `sum` adds them.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "numbers = list(map(int, input().split()))\n",
    "odds = filter(lambda n: n % 2 == 1, numbers)\n",
    "squares = map(lambda n: n ** 2, odds)\n",
    "print(sum(squares))\n",
    "```\n",
    "\n",
    "**Test cases**\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `1 2 3 4 5 6` | `35` |\n",
    "| `2 4 6` | `0` |\n",
    "| `7` | `49` |\n",
    "| `-3 2` | `9` |\n",
    "| `1 1 1` | `3` |\n",
    "\n",
    "</details>"
   ],
   "id": "t04p-042"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 14. Zeros to the end\n",
    "\n",
    "Read a list of numbers and move all zeros to the end, keeping the order of the other numbers. Print the new list. Example: `0 3 0 5 1` gives `[3, 5, 1, 0, 0]`.\n",
    "\n",
    "Examples\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `0 3 0 5 1` | `[3, 5, 1, 0, 0]` |\n",
    "| `1 2 3` | `[1, 2, 3]` |\n",
    "| `0 0 0` | `[0, 0, 0]` |\n",
    "| `0 7` | `[7, 0]` |\n",
    "| `4 0 0 9 0` | `[4, 9, 0, 0, 0]` |"
   ],
   "id": "t04p-043"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "asiman": {
     "typed": [
      "0 3 0 5 1"
     ]
    }
   },
   "outputs": [],
   "source": [
    "numbers = list(map(int, input().split()))\n",
    "# Write your code here"
   ],
   "id": "t04p-044"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "Make a list of the numbers that are not zero. Count the zeros with `count(0)`. Then join: `others + [0] * zeros`.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "numbers = list(map(int, input().split()))\n",
    "others = list(filter(lambda n: n != 0, numbers))\n",
    "zeros = numbers.count(0)\n",
    "print(others + [0] * zeros)\n",
    "```\n",
    "\n",
    "**Test cases**\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `0 3 0 5 1` | `[3, 5, 1, 0, 0]` |\n",
    "| `1 2 3` | `[1, 2, 3]` |\n",
    "| `0 0 0` | `[0, 0, 0]` |\n",
    "| `0 7` | `[7, 0]` |\n",
    "| `4 0 0 9 0` | `[4, 9, 0, 0, 0]` |\n",
    "\n",
    "</details>"
   ],
   "id": "t04p-045"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 15. Rotate to the right\n",
    "\n",
    "Read a list of numbers and rotate it `k` steps to the right (`k` is on the second line). Print the list. Example: `1 2 3 4 5` with `k = 2` gives `[4, 5, 1, 2, 3]`.\n",
    "\n",
    "Examples\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `1 2 3 4 5, 2` | `[4, 5, 1, 2, 3]` |\n",
    "| `1 2 3, 0` | `[1, 2, 3]` |\n",
    "| `1 2 3, 3` | `[1, 2, 3]` |\n",
    "| `7, 4` | `[7]` |\n",
    "| `1 2 3 4, 1` | `[4, 1, 2, 3]` |\n",
    "| `1 2 3 4 5, 7` | `[4, 5, 1, 2, 3]` |"
   ],
   "id": "t04p-046"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "asiman": {
     "typed": [
      "1 2 3 4 5",
      "2"
     ]
    }
   },
   "outputs": [],
   "source": [
    "numbers = list(map(int, input().split()))\n",
    "k = int(input())\n",
    "# Write your code here"
   ],
   "id": "t04p-047"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "One step: `pop()` takes the last item and `insert(0, ...)` puts it in front (solved problem 22). Repeat it `k` times with a loop.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "numbers = list(map(int, input().split()))\n",
    "k = int(input())\n",
    "for step in range(k):\n",
    "    last = numbers.pop()\n",
    "    numbers.insert(0, last)\n",
    "print(numbers)\n",
    "```\n",
    "\n",
    "**Test cases**\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `1 2 3 4 5, 2` | `[4, 5, 1, 2, 3]` |\n",
    "| `1 2 3, 0` | `[1, 2, 3]` |\n",
    "| `1 2 3, 3` | `[1, 2, 3]` |\n",
    "| `7, 4` | `[7]` |\n",
    "| `1 2 3 4, 1` | `[4, 1, 2, 3]` |\n",
    "| `1 2 3 4 5, 7` | `[4, 5, 1, 2, 3]` |\n",
    "\n",
    "</details>"
   ],
   "id": "t04p-048"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "When you have finished, compare your solutions with the hidden ones. A different solution that passes every example is just as good."
   ],
   "id": "t04p-049"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
