diff --git a/notebooks/introduction-python/exercises.ipynb b/notebooks/introduction-python/exercises.ipynb index 33c8443..7c08bab 100644 --- a/notebooks/introduction-python/exercises.ipynb +++ b/notebooks/introduction-python/exercises.ipynb @@ -57,11 +57,11 @@ " print(k)" ], "metadata": { - "id": "j0bQ92RpJxJD", - "outputId": "2da549f3-8e2c-4b63-b9f0-9112880bc556", "colab": { "base_uri": "https://localhost:8080/" - } + }, + "id": "j0bQ92RpJxJD", + "outputId": "2da549f3-8e2c-4b63-b9f0-9112880bc556" }, "execution_count": 4, "outputs": [ @@ -116,11 +116,11 @@ "merge(dict1, dict2, dict3)" ], "metadata": { - "id": "31pMhyRxIlXk", - "outputId": "cb4dd71e-316c-43ed-8c13-b418e82f4735", "colab": { "base_uri": "https://localhost:8080/" - } + }, + "id": "31pMhyRxIlXk", + "outputId": "cb4dd71e-316c-43ed-8c13-b418e82f4735" }, "execution_count": 6, "outputs": [ @@ -157,6 +157,33 @@ "id": "LZJsa8ZR0zP3" } }, + { + "cell_type": "code", + "source": [ + "a = [1, 2, [3, 4]]\n", + "b = list(a)\n", + "\n", + "b[2][0] = -100\n", + "print(a)" + ], + "metadata": { + "id": "Lb7OAnhfLPBI", + "outputId": "28b704b0-310f-4f04-da69-3e42ae4e5152", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "execution_count": 8, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[1, 2, [-100, 4]]\n" + ] + } + ] + }, { "cell_type": "markdown", "metadata": { @@ -186,6 +213,113 @@ ":::" ] }, + { + "cell_type": "code", + "source": [ + "[i for i in str(-5438543)]" + ], + "metadata": { + "id": "EQsCkCB-PS-9", + "outputId": "2451f1e3-043e-404d-b536-853d22186691", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "execution_count": 18, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "['-', '5', '4', '3', '8', '5', '4', '3']" + ] + }, + "metadata": {}, + "execution_count": 18 + } + ] + }, + { + "cell_type": "code", + "source": [ + "def traduce(objeto):\n", + " if isinstance(objeto, int) and not isinstance(objeto, bool):\n", + " return traduce_entero(objeto)\n", + "\n", + " if isinstance(objeto, float):\n", + " return traduce_flotante(objeto)\n", + "\n", + " if isinstance(objeto, str):\n", + " return objeto\n", + "\n", + " return \"\"\n", + "\n", + "def traduce_entero(n):\n", + " n_str = str(n)\n", + " digits = [i for i in n_str]\n", + " return \"-\".join([traduce_digito(digit) for digit in digits])\n", + "\n", + "traductor_digitos = {\n", + " \"1\": \"uno\",\n", + " \"2\": \"dos\",\n", + " \"3\": \"tres\",\n", + " \"4\": \"cuatro\",\n", + " \"5\": \"cinco\",\n", + " \"6\": \"seis\",\n", + " \"7\": \"siete\",\n", + " \"8\": \"ocho\",\n", + " \"9\": \"nueve\",\n", + " \"0\": \"cero\",\n", + " \"-\": \"menos\"\n", + "}\n", + "\n", + "def traduce_digito(digito):\n", + " return traductor_digitos[digito]\n", + "\n", + "def traduce_flotante(f):\n", + " f_rounded = round(f)\n", + " return traduce_entero(f_rounded) + \" y decimales\"\n", + "\n", + "def concat_to_str(iterable):\n", + " traducciones = [traduce(i) for i in iterable]\n", + " return \" | \".join(traducciones)" + ], + "metadata": { + "id": "VuCGnWA0NI_n" + }, + "execution_count": 22, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "concat_to_str([12, -14.23, \"hello\", True, None, 10.1, -5])" + ], + "metadata": { + "id": "bBzRmtoYPFCx", + "outputId": "3fa62372-1e1f-489e-fec7-7cf1d9e39039", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 36 + } + }, + "execution_count": 23, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'uno-dos | menos-uno-cuatro y decimales | hello | | | uno-cero y decimales | menos-cinco'" + ], + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + } + }, + "metadata": {}, + "execution_count": 23 + } + ] + }, { "cell_type": "markdown", "source": [