{ "cells": [ { "cell_type": "markdown", "id": "f32a0823-7023-409b-b572-19213fd9c56a", "metadata": {}, "source": [ "# More Python Exercises\n", "\n", "Feel like you've got it down? Here are a few more exercises to try!" ] }, { "cell_type": "markdown", "id": "af3ddec1-07e8-48eb-8f03-3fbe1e4b22ea", "metadata": {}, "source": [ "### Reverse an integer\n", "\n", "Write some code to reverse an integer. For example, 8291 becomes 1928. The result should be an integer as well!" ] }, { "cell_type": "code", "execution_count": null, "id": "97fce3cf-5c7f-40e5-80e6-b0747aea2f81", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "89c4c651-48dd-4e5a-b097-7556fc2b42c4", "metadata": {}, "source": [ "### Remove from a list\n", "\n", "Write some code to remove a target value from a list of strings. For example if the list is\n", "\n", "```[\"I\", \"love\", \"to\", \"eat\", \"cake\", \"and\", \"I\", \"love\", \"to\", \"eat\", \"pie\"]```\n", "\n", "And the target to remove is \"love\", then the result should be\n", "\n", "```[\"I\", \"to\", \"eat\", \"cake\", \"and\", \"I\", \"to\", \"eat\", \"pie\"]```" ] }, { "cell_type": "code", "execution_count": null, "id": "41b58d16-ce6e-4a90-b820-d67fa2267405", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "03c9f7a5-52aa-41bb-8afe-161abf315905", "metadata": {}, "source": [ "### Make a dictionary from two lists\n", "\n", "Take two lists and make a dictionary. For example, if the lists are\n", "\n", "```\n", "listA = [\"a\", \"b\", \"c\"]\n", "listB = [1, 2, 3]\n", "```\n", "\n", "Then the result should be\n", "\n", "```{\"a\": 1, \"b\": 2, \"c\": 3}```" ] }, { "cell_type": "code", "execution_count": null, "id": "92e53b25-f2eb-4fed-9e04-a73a806f34ba", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "3c6c1df3-a3fe-42d8-ba22-b7edc1ef026f", "metadata": {}, "source": [ "### Count the words\n", "\n", "Given a string, count the number of times words appear in the string as a dictionary. For example, if the string is\n", "\n", "```I love to eat cake and I love to eat pie```\n", "\n", "Then the result should be\n", "\n", "```{\"I\": 2, \"love\": 2, \"to\": 2, \"eat\": 2, \"cake\": 1, \"and\": 1, \"pie\": 1}```" ] }, { "cell_type": "code", "execution_count": null, "id": "61e5fdea-a82e-4af9-8cec-64d4013fab1a", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "bb3170c6-0ec4-4f07-9f87-e5dee1eacafb", "metadata": {}, "source": [ "### Calculate the intersection of two lists\n", "\n", "Given two lists, return only the items that are present in both lists (as another list)." ] }, { "cell_type": "code", "execution_count": null, "id": "00b5873b-81c7-4591-8e5c-f55866153066", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "fd14d0b0-a69c-46e1-8614-7bb35ec202b1", "metadata": {}, "source": [ "### Filter a list\n", "\n", "Given two lists, return only the items from the first list that are NOT present in the second list. Do not modify either original list." ] }, { "cell_type": "code", "execution_count": null, "id": "e77889aa-a62a-43cd-909d-5ff82a919c2d", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "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.11.11" } }, "nbformat": 4, "nbformat_minor": 5 }