From e04a99a9bfbc3c78dcb3d67ecf1f19f674f76711 Mon Sep 17 00:00:00 2001 From: bperezlovisolo Date: Thu, 5 Feb 2026 12:33:28 +0100 Subject: [PATCH 1/2] lab-python-compre-extra --- lab-python-list-comprehension.ipynb | 69 ++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 12 deletions(-) diff --git a/lab-python-list-comprehension.ipynb b/lab-python-list-comprehension.ipynb index 6bef7fd..20af524 100644 --- a/lab-python-list-comprehension.ipynb +++ b/lab-python-list-comprehension.ipynb @@ -74,9 +74,28 @@ "execution_count": null, "id": "21625526-3fae-4c55-bab5-f91940070681", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['Open', 'Open', 'Senior', 'Open', 'Open', 'Senior']" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code goes here" + "# your code goes here\n", + "\n", + "prospects = [[18, 20], [45, 2], [61, 12], [37, 6], [21, 21], [78, 9]]\n", + "\n", + "cat_member = [\"Senior\" if p[0] >= 55 and p[1] > 7 else \"Open\" for p in prospects]\n", + "cat_member\n", + "\n", + "#senior member 55 y and handicap <7\n", + "#mejor jugador - valor de handicap" ] }, { @@ -100,7 +119,11 @@ "metadata": {}, "outputs": [], "source": [ - "# your code goes here" + "# your code goes here\n", + "def suma_multiples(n):\n", + " multiples = [x for x in range(n) if x % 3 == 0 or x % 5 == 0]\n", + " result = sum(multiples)\n", + " return result" ] }, { @@ -132,7 +155,11 @@ "metadata": {}, "outputs": [], "source": [ - "# your code goes here" + "# your code goes here\n", + "\n", + "def new_list(n):\n", + " separados =[int(x) for x in str(n)]\n", + " return separados" ] }, { @@ -160,7 +187,10 @@ "metadata": {}, "outputs": [], "source": [ - "# your code goes here" + "# your code goes here\n", + "def inversa(num):\n", + " result = [-x for x in num]\n", + " return result" ] }, { @@ -198,7 +228,9 @@ "metadata": {}, "outputs": [], "source": [ - "# your code goes here" + "# your code goes here\n", + "\n", + "new_dict = {key:key**2 for key in range(1,16)}" ] }, { @@ -225,7 +257,10 @@ "metadata": {}, "outputs": [], "source": [ - "# your code goes here" + "# your code goes here\n", + "def nueva_lista(lista1, lista2):\n", + " new_list = [(x,y) for x in lista1 for y in lista2]\n", + " return new_list" ] }, { @@ -251,7 +286,10 @@ "metadata": {}, "outputs": [], "source": [ - "# your code goes here" + "# your code goes here\n", + "def lista_dic(diccionario):\n", + " new_list = [(k, v) for k, values in diccionario.items() for v in values]\n", + " return new_list" ] }, { @@ -286,7 +324,11 @@ "metadata": {}, "outputs": [], "source": [ - "# your code goes here" + "# your code goes here\n", + "\n", + "def tuplas_v(tupla):\n", + " new_list = [(num1, num2) for lista1, lista2 in tupla for num1 in lista1 for num2 in lista2]\n", + " return new_list" ] }, { @@ -313,13 +355,16 @@ "metadata": {}, "outputs": [], "source": [ - "# your code goes here" + "# your code goes here\n", + "def nuevo_diccionario(list_string):\n", + " new_set = {(a, b) for a in list_string[0] for b in list_string[1]}\n", + " return new_set" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -333,7 +378,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.2" } }, "nbformat": 4, From c1bc300ba7ff31c6cfa807526276b9f2d8c3064a Mon Sep 17 00:00:00 2001 From: bperezlovisolo Date: Thu, 5 Feb 2026 12:40:59 +0100 Subject: [PATCH 2/2] correcion --- lab-python-list-comprehension.ipynb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lab-python-list-comprehension.ipynb b/lab-python-list-comprehension.ipynb index 20af524..95edc33 100644 --- a/lab-python-list-comprehension.ipynb +++ b/lab-python-list-comprehension.ipynb @@ -121,9 +121,9 @@ "source": [ "# your code goes here\n", "def suma_multiples(n):\n", - " multiples = [x for x in range(n) if x % 3 == 0 or x % 5 == 0]\n", - " result = sum(multiples)\n", - " return result" + " if n < 0:\n", + " return 0\n", + " return sum([x for x in range(n) if x % 3 == 0 or x % 5 == 0])" ] }, {