diff --git a/your-code/challenges.ipynb b/your-code/challenges.ipynb index ba91b3f..5c1ecbe 100644 --- a/your-code/challenges.ipynb +++ b/your-code/challenges.ipynb @@ -13,11 +13,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'i'" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "mi_tupla= (\"i\") #declaramos la tupla\n", + "mi_tupla" ] }, { @@ -31,11 +44,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mi tupla contiene:i\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "print(f\"Mi tupla contiene:{mi_tupla}\")" ] }, { @@ -53,15 +75,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "ename": "AttributeError", + "evalue": "'str' object has no attribute 'append'", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mAttributeError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[5]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;66;03m# Your code here\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m \u001b[43mmi_tupla\u001b[49m\u001b[43m.\u001b[49m\u001b[43mappend\u001b[49m(\u001b[33m\"\u001b[39m\u001b[33ma\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m 3\u001b[39m \u001b[38;5;66;03m# Your explanation here\u001b[39;00m\n\u001b[32m 4\u001b[39m \u001b[38;5;66;03m# La tupla es un objeto inmutable dentro del codigo, no es posible ingresar, eliminar, ni modificar el valor de la tupla una vez este es declarado\u001b[39;00m\n\u001b[32m 5\u001b[39m \u001b[38;5;66;03m# You can :) \u001b[39;00m\n", + "\u001b[31mAttributeError\u001b[39m: 'str' object has no attribute 'append'" + ] + } + ], "source": [ "# Your code here\n", - "\n", + "mi_tupla.append(\"a\")\n", "# Your explanation here\n", + "# La tupla es un objeto inmutable dentro del codigo, no es posible ingresar, eliminar, ni modificar el valor de la tupla una vez este es declarado\n", "# You can :) " ] }, @@ -80,11 +115,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mi nueva tupla contiene: ('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "mi_tupla = (\"I\",)#se deja una \",\" para que python interprete que no es una cadena de texto \n", + " # para que python entienda que es una tupla de un solo elemento debo poner \",\" al final\n", + "mi_tupla2 = (\"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n", + "re_tupla= mi_tupla + mi_tupla2 #creo una nueva tupla a partir de las 2 anteriores aunque las 2 anteriores mantengan sus valores\n", + "print(f\"Mi nueva tupla contiene: {re_tupla}\")" ] }, { @@ -102,11 +150,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mi tupla 1 es: ('I', 'r', 'o', 'n') y mi tupla 2 es:('h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "tup1= re_tupla[0:4]#usamos slicing para asigunar valores a la nueva tupla\n", + "tup2= re_tupla[-4:]\n", + "print(f\"Mi tupla 1 es: {tup1} y mi tupla 2 es:{tup2}\")\n" ] }, { @@ -120,11 +179,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Las 2 Tupplas son iguales\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "tup3 = tup1+tup2\n", + "if tup3 == re_tupla: #condicionamos y verificamos si la variables son iguales\n", + " print(\"Las 2 Tupplas son iguales\")\n", + "else:\n", + " print(\"no son iguales\")" ] }, { @@ -136,11 +208,47 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mi tupla 3 contiene 4 elementos\n", + "\n", + "Mi tupla 3 contiene 4 elementos\n", + "\n", + "Mi tupla 3 contiene 8 elementos\n", + "\n", + "La suma de tuplas 1 y 2: 8 contienen la misma cantidad de datos que la tupla 3: 8\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "a = 0 #iniciamos contadores en 0\n", + "b = 0\n", + "c = 0 \n", + "for h in tup1: #hacemos un bucle for para poder contar la cantidad de variables dentro de la tuppla\n", + " a = a+1 #llenamos la variable\n", + "print(f\"Mi tupla 3 contiene {a} elementos\\n\") \n", + "\n", + "for i in tup2:\n", + " b = b+1\n", + "print(f\"Mi tupla 3 contiene {b} elementos\\n\")\n", + "\n", + "for j in tup3:\n", + " c = c+1\n", + "print(f\"Mi tupla 3 contiene {c} elementos\\n\") \n", + "\n", + "d = a + b\n", + "\n", + "if d == c:\n", + " print(f\"La suma de tuplas 1 y 2: {d} contienen la misma cantidad de datos que la tupla 3: {c}\")\n", + "else:\n", + " print(\"Las tuplas no suman lo mismo\")\n", + "\n" ] }, { @@ -152,11 +260,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'h'" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "tup3[4]" ] }, { @@ -176,20 +296,51 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "La lista contiene:a\n", + "La lista contiene:b\n", + "La lista contiene:c\n", + "La lista contiene:d\n", + "La lista contiene:e\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n", + "for i in letters:\n", + " print(f\"La lista contiene:{i}\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "El valor de i: a se encuentra en tup3? True\n", + "El valor de i: b se encuentra en tup3? False\n", + "El valor de i: c se encuentra en tup3? True\n", + "El valor de i: d se encuentra en tup3? False\n", + "El valor de i: e se encuentra en tup3? False\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n", + "for i in letters:\n", + " print( \"El valor de i:\", i, \"se encuentra en tup3?\", i in tup3 ) \n", + " #le indicamos que nos imprima si es correcto que hay un valor igual sino nos indicara que no lo hay" ] }, { @@ -203,11 +354,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hay 2 valores de tup3 en la lista de letras\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n", + "a=0\n", + "for i in letters:\n", + " if i in tup3:\n", + " a = a+1\n", + "print(f\"Hay {a} valores de tup3 en la lista de letras\")\n", + " " ] }, { @@ -223,11 +389,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ - "import random" + "import random as rn" ] }, { @@ -248,11 +414,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Lista Final: [228, 271, 444, 459, 467, 596, 751, 870, 937, 991] \n", + "\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "sample_list_1 = []\n", + "b=[]\n", + "a = int(input(\"Ingrese la cantidad de valores\"))#le pedimos que nos diga cuantos numeros valores le daremos a la lista\n", + "b = rn.sample(range(1,1001),a) #b nos devolvera una serie de numeros en un rango especificado y la cantidad de veces que se repita \"a\"\n", + "valor =[] \n", + "for i in range(a): \n", + " while True: #generamos un while que siempre que sea cierto nos ira arrojando valores en el rango que le dimos\n", + " valor = rn.sample(b,1)\n", + " if valor[0] not in sample_list_1: #le indicamos que no puede repetirse el valor y nos dara valores unicos\n", + " sample_list_1.append(valor[0])#ingresamos el valor dentro del indice de la lista\n", + " break\n", + "sample_list_1.sort() #ordenamos la lista\n", + "print(\"Lista Final:\", sample_list_1,\"\\n\")#la imprimimos\n" ] }, { @@ -264,11 +452,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10\n" + ] + } + ], "source": [ - "# your code here" + "# your code here\n", + "cvacio = set()\n", + "ml= sample_list_1\n", + "set1 = set(ml)\n", + "print(len(set1))" ] }, { @@ -287,11 +487,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Lista Final: [5, 8, 77, 138, 195, 359, 560, 568, 865, 878] \n", + "\n" + ] + } + ], "source": [ - "# your code here" + "sample_list_2 = []\n", + "b=[]\n", + "o = int(input(\"Ingrese la cantidad de valores\"))#le pedimos que nos diga cuantos numeros valores le daremos a la lista\n", + "f = rn.sample(range(1,1001),a) #b nos devolvera una serie de numeros en un rango especificado y la cantidad de veces que se repita \"a\"\n", + "valor1 =[] \n", + "for i in range(a):\n", + " while True:#generamos un while que siempre que sea cierto nos ira arrojando valores en el rango que le dimos\n", + " valor1 = rn.sample(f,1)\n", + " if valor1[0] not in sample_list_2:#le indicamos que no puede repetirse el valor y nos dara valores unicos\n", + " sample_list_2.append(valor1[0])\n", + " break\n", + "sample_list_2.sort() #ordenamos la lista\n", + "print(\"Lista Final:\", sample_list_2,\"\\n\")#la imprimimos# your code here" ] }, { @@ -303,11 +524,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "80\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code herecvacio = set()\n", + "ml2= sample_list_2\n", + "set2 = set(ml2)\n", + "print(len(set1))" ] }, { @@ -319,11 +551,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 43, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{512, 128, 640, 768, 770, 5, 775, 137, 270, 401, 658, 277, 22, 25, 922, 923, 540, 412, 158, 926, 34, 549, 38, 430, 303, 48, 49, 818, 692, 820, 566, 821, 191, 832, 449, 706, 67, 963, 456, 329, 842, 205, 846, 82, 598, 215, 727, 984, 475, 988, 94, 862, 97, 609, 355, 612, 101, 229, 869, 485, 487, 488, 876, 365, 111, 112, 754, 499, 628, 373, 501, 632, 124, 637}\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "set3= set()\n", + "for i in set1:\n", + " if i not in set2:\n", + " set3.add(i)\n", + "print(set3)" ] }, { @@ -335,11 +580,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 44, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{897, 515, 255, 645, 259, 772, 773, 265, 389, 139, 780, 390, 394, 271, 20, 149, 916, 917, 920, 921, 538, 667, 411, 31, 33, 161, 673, 421, 39, 936, 809, 298, 810, 938, 940, 814, 433, 950, 568, 57, 313, 443, 575, 63, 68, 708, 710, 583, 72, 711, 326, 460, 334, 210, 217, 473, 859, 606, 102, 232, 744, 874, 108, 366, 494, 496, 113, 241, 497, 885, 758, 631, 508, 639}\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "set4= set()\n", + "for j in set2:\n", + " if j not in set1:\n", + " set4.add(j)\n", + "print(set4)" ] }, { @@ -351,11 +609,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{674, 867, 43, 971, 945, 317}\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "set5 = set1 & set2\n", + "print(set5)" ] }, { @@ -375,11 +643,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'set1' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mNameError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[1]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;66;03m# Your code here\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28mlen\u001b[39m(\u001b[43mset1\u001b[49m),\u001b[38;5;28mlen\u001b[39m(set2),\u001b[38;5;28mlen\u001b[39m(set3),\u001b[38;5;28mlen\u001b[39m(set4),\u001b[38;5;28mlen\u001b[39m(set5))\n\u001b[32m 3\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28mlen\u001b[39m(set3) == \u001b[38;5;28mlen\u001b[39m(set1 - set2)) \n\u001b[32m 4\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28mlen\u001b[39m(set4) == \u001b[38;5;28mlen\u001b[39m(set2 - set1)) \n", + "\u001b[31mNameError\u001b[39m: name 'set1' is not defined" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "print(len(set1),len(set2),len(set3),len(set4),len(set5))\n", + "print(len(set3) == len(set1 - set2)) \n", + "print(len(set4) == len(set2 - set1)) \n", + "print(len(set5) == len(set1 & set2))" ] }, { @@ -395,7 +679,8 @@ "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "# Your code here\n", + "set6 = set()" ] }, { @@ -407,11 +692,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 49, "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "# Your code here\n", + "set6 = set3.update(set5)" ] }, { @@ -423,11 +709,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 50, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "print(set1 == set6)" ] }, { @@ -439,11 +734,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 55, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "el set1 se encuentre en el set2: False\n", + "el set1 se encuentre en el set3: True\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "print(\"el set1 se encuentre en el set2:\",set1.issubset(set2))\n", + "print(\"el set1 se encuentre en el set3:\",set1.issubset(set3))" ] }, { @@ -457,11 +763,43 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 63, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "El sett es:\n", + " {512, 515, 5, 20, 22, 25, 538, 540, 31, 33, 34, 549, 38, 39, 43, 48, 49, 566, 568, 57, 575, 63, 67, 68, 583, 72, 82, 598, 94, 606, 97, 609, 612, 101, 102, 108, 111, 112, 113, 628, 631, 632, 124, 637, 639, 128, 640, 645, 137, 139, 658, 149, 667, 158, 161, 674, 673, 692, 191, 706, 708, 710, 711, 205, 210, 215, 727, 217, 229, 232, 744, 241, 754, 758, 255, 768, 770, 259, 772, 773, 775, 265, 780, 270, 271, 277, 809, 298, 810, 814, 303, 818, 820, 821, 313, 317, 832, 326, 329, 842, 846, 334, 859, 862, 355, 867, 869, 874, 876, 365, 366, 373, 885, 897, 389, 390, 394, 401, 916, 917, 920, 921, 922, 923, 412, 411, 926, 421, 936, 938, 940, 430, 945, 433, 950, 443, 449, 963, 456, 971, 460, 984, 473, 475, 988, 485, 487, 488, 494, 496, 497, 499, 501, 508}\n", + "\n", + "\n", + "154\n", + "\n", + "\n", + "El sett2 es:\n", + " {512, 515, 5, 20, 22, 25, 538, 540, 31, 33, 34, 549, 38, 39, 43, 48, 49, 566, 568, 57, 575, 63, 67, 68, 583, 72, 82, 598, 94, 606, 97, 609, 612, 101, 102, 108, 111, 112, 113, 628, 631, 632, 124, 637, 639, 128, 640, 645, 137, 139, 658, 149, 667, 158, 161, 674, 673, 692, 191, 706, 708, 710, 711, 205, 210, 215, 727, 217, 229, 232, 744, 241, 754, 758, 255, 768, 770, 259, 772, 773, 775, 265, 780, 270, 271, 277, 809, 298, 810, 814, 303, 818, 820, 821, 313, 317, 832, 326, 329, 842, 846, 334, 859, 862, 355, 867, 869, 874, 876, 365, 366, 373, 885, 897, 389, 390, 394, 401, 916, 917, 920, 921, 922, 923, 412, 411, 926, 421, 936, 938, 940, 430, 945, 433, 950, 443, 449, 963, 456, 971, 460, 984, 473, 475, 988, 485, 487, 488, 494, 496, 497, 499, 501, 508}\n", + "\n", + "\n", + "154\n", + "\n", + "\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "sett= set()\n", + "sett= set3.union(set3,set4,set5)\n", + "print(\"El sett es:\\n\", sett)\n", + "print(\"\\n\")\n", + "print(len(sett))\n", + "print(\"\\n\")\n", + "sett2 = sett.union(set1,set2)\n", + "print(\"El sett2 es:\\n\", sett2)\n", + "print(\"\\n\")\n", + "print(len(sett2))\n", + "print(\"\\n\")" ] }, { @@ -473,11 +811,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 70, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{22, 25, 540, 34, 549, 38, 43, 48, 49, 566, 67, 82, 598, 94, 97, 609, 612, 101, 111, 112, 628, 632, 124, 637, 128, 640, 137, 658, 158, 674, 692, 191, 706, 205, 215, 727, 229, 754, 768, 770, 775, 270, 277, 303, 818, 820, 821, 317, 832, 329, 842, 846, 862, 355, 867, 869, 876, 365, 373, 401, 922, 923, 412, 926, 430, 945, 449, 963, 456, 971, 984, 475, 988, 485, 487, 488, 499, 501}\n", + "\n", + "\n", + "22\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "print(set1)\n", + "print(\"\\n\")\n", + "a=set1.pop()\n", + "print(a)\n", + "#con pop no se puede eliminar un elemento en espeficico" ] }, { @@ -493,11 +847,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 73, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{25, 540, 34, 549, 38, 43, 48, 566, 67, 82, 598, 94, 97, 609, 612, 101, 111, 112, 628, 632, 124, 637, 128, 640, 137, 658, 158, 674, 692, 191, 706, 205, 215, 727, 229, 754, 768, 770, 775, 270, 277, 303, 818, 820, 821, 317, 832, 329, 842, 846, 862, 355, 867, 869, 876, 365, 373, 401, 922, 923, 412, 926, 430, 945, 449, 963, 456, 971, 984, 475, 988, 485, 487, 488, 499, 501}\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "list_to_remove = [1, 9, 11, 19, 21, 29, 31, 39, 41, 49, 51, 59, 61, 69, 71, 79, 81, 89, 91, 99]\n", + "for i in list_to_remove:\n", + " if i in set1:\n", + " set1.remove(i)\n", + "print(set1)" ] }, { @@ -515,11 +882,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ - "word_freq = {'love': 25, 'conversation': 1, 'every': 6, \"we're\": 1, 'plate': 1, 'sour': 1, 'jukebox': 1, 'now': 11, 'taxi': 1, 'fast': 1, 'bag': 1, 'man': 1, 'push': 3, 'baby': 14, 'going': 1, 'you': 16, \"don't\": 2, 'one': 1, 'mind': 2, 'backseat': 1, 'friends': 1, 'then': 3, 'know': 2, 'take': 1, 'play': 1, 'okay': 1, 'so': 2, 'begin': 1, 'start': 2, 'over': 1, 'body': 17, 'boy': 2, 'just': 1, 'we': 7, 'are': 1, 'girl': 2, 'tell': 1, 'singing': 2, 'drinking': 1, 'put': 3, 'our': 1, 'where': 1, \"i'll\": 1, 'all': 1, \"isn't\": 1, 'make': 1, 'lover': 1, 'get': 1, 'radio': 1, 'give': 1, \"i'm\": 23, 'like': 10, 'can': 1, 'doing': 2, 'with': 22, 'club': 1, 'come': 37, 'it': 1, 'somebody': 2, 'handmade': 2, 'out': 1, 'new': 6, 'room': 3, 'chance': 1, 'follow': 6, 'in': 27, 'may': 2, 'brand': 6, 'that': 2, 'magnet': 3, 'up': 3, 'first': 1, 'and': 23, 'pull': 3, 'of': 6, 'table': 1, 'much': 2, 'last': 3, 'i': 6, 'thrifty': 1, 'grab': 2, 'was': 2, 'driver': 1, 'slow': 1, 'dance': 1, 'the': 18, 'say': 2, 'trust': 1, 'family': 1, 'week': 1, 'date': 1, 'me': 10, 'do': 3, 'waist': 2, 'smell': 3, 'day': 6, 'although': 3, 'your': 21, 'leave': 1, 'want': 2, \"let's\": 2, 'lead': 6, 'at': 1, 'hand': 1, 'how': 1, 'talk': 4, 'not': 2, 'eat': 1, 'falling': 3, 'about': 1, 'story': 1, 'sweet': 1, 'best': 1, 'crazy': 2, 'let': 1, 'too': 5, 'van': 1, 'shots': 1, 'go': 2, 'to': 2, 'a': 8, 'my': 33, 'is': 5, 'place': 1, 'find': 1, 'shape': 6, 'on': 40, 'kiss': 1, 'were': 3, 'night': 3, 'heart': 3, 'for': 3, 'discovering': 6, 'something': 6, 'be': 16, 'bedsheets': 3, 'fill': 2, 'hours': 2, 'stop': 1, 'bar': 1}" + "word_freq = {'love': 25, 'conversation': 1, 'every': 6, \"we're\": 1, 'plate': 1, 'sour': 1, \n", + " 'jukebox': 1, 'now': 11, 'taxi': 1, 'fast': 1, 'bag': 1, 'man': 1, 'push': 3, \n", + " 'baby': 14, 'going': 1, 'you': 16, \"don't\": 2, 'one': 1, 'mind': 2, 'backseat': 1,\n", + " 'friends': 1, 'then': 3, 'know': 2, 'take': 1, 'play': 1, 'okay': 1, 'so': 2, 'begin': 1,\n", + " 'start': 2, 'over': 1, 'body': 17, 'boy': 2, 'just': 1, 'we': 7, 'are': 1, 'girl': 2, \n", + " 'tell': 1, 'singing': 2, 'drinking': 1, 'put': 3, 'our': 1, 'where': 1, \"i'll\": 1, 'all': 1, \n", + " \"isn't\": 1, 'make': 1, 'lover': 1, 'get': 1, 'radio': 1, 'give': 1, \"i'm\": 23, 'like': 10, \n", + " 'can': 1, 'doing': 2, 'with': 22, 'club': 1, 'come': 37, 'it': 1, 'somebody': 2, 'handmade': 2,\n", + " 'out': 1, 'new': 6, 'room': 3, 'chance': 1, 'follow': 6, 'in': 27, 'may': 2, 'brand': 6, \n", + " 'that': 2, 'magnet': 3, 'up': 3, 'first': 1, 'and': 23, 'pull': 3, 'of': 6, 'table': 1, 'much': 2,\n", + " 'last': 3, 'i': 6, 'thrifty': 1, 'grab': 2, 'was': 2, 'driver': 1, 'slow': 1, 'dance': 1, \n", + " 'the': 18, 'say': 2, 'trust': 1, 'family': 1, 'week': 1, 'date': 1, 'me': 10, 'do': 3, 'waist': 2, \n", + " 'smell': 3, 'day': 6, 'although': 3, 'your': 21, 'leave': 1, 'want': 2, \"let's\": 2, 'lead': 6, 'at': 1,\n", + " 'hand': 1, 'how': 1, 'talk': 4, 'not': 2, 'eat': 1, 'falling': 3, 'about': 1, 'story': 1, 'sweet': 1, \n", + " 'best': 1, 'crazy': 2, 'let': 1, 'too': 5, 'van': 1, 'shots': 1, 'go': 2, 'to': 2, 'a': 8, 'my': 33, \n", + " 'is': 5, 'place': 1, 'find': 1, 'shape': 6, 'on': 40, 'kiss': 1, 'were': 3, 'night': 3, 'heart': 3, \n", + " 'for': 3, 'discovering': 6, 'something': 6, 'be': 16, 'bedsheets': 3, 'fill': 2, 'hours': 2, \n", + " 'stop': 1, 'bar': 1}" ] }, { @@ -551,11 +935,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['a', 'about', 'all', 'although', 'and', 'are', 'at', 'baby', 'backseat', 'bag', 'bar', 'be', 'bedsheets', 'begin', 'best', 'body', 'boy', 'brand', 'can', 'chance', 'club', 'come', 'conversation', 'crazy', 'dance', 'date', 'day', 'discovering', 'do', 'doing', \"don't\", 'drinking', 'driver', 'eat', 'every', 'falling', 'family', 'fast', 'fill', 'find', 'first', 'follow', 'for', 'friends', 'get', 'girl', 'give', 'go', 'going', 'grab', 'hand', 'handmade', 'heart', 'hours', 'how', 'i', \"i'll\", \"i'm\", 'in', 'is', \"isn't\", 'it', 'jukebox', 'just', 'kiss', 'know', 'last', 'lead', 'leave', 'let', \"let's\", 'like', 'love', 'lover', 'magnet', 'make', 'man', 'may', 'me', 'mind', 'much', 'my', 'new', 'night', 'not', 'now', 'of', 'okay', 'on', 'one', 'our', 'out', 'over', 'place', 'plate', 'play', 'pull', 'push', 'put', 'radio', 'room', 'say', 'shape', 'shots', 'singing', 'slow', 'smell', 'so', 'somebody', 'something', 'sour', 'start', 'stop', 'story', 'sweet', 'table', 'take', 'talk', 'taxi', 'tell', 'that', 'the', 'then', 'thrifty', 'to', 'too', 'trust', 'up', 'van', 'waist', 'want', 'was', 'we', \"we're\", 'week', 'were', 'where', 'with', 'you', 'your']\n", + "{'a': 8, 'about': 1, 'all': 1, 'although': 3, 'and': 23, 'are': 1, 'at': 1, 'baby': 14, 'backseat': 1, 'bag': 1, 'bar': 1, 'be': 16, 'bedsheets': 3, 'begin': 1, 'best': 1, 'body': 17, 'boy': 2, 'brand': 6, 'can': 1, 'chance': 1, 'club': 1, 'come': 37, 'conversation': 1, 'crazy': 2, 'dance': 1, 'date': 1, 'day': 6, 'discovering': 6, 'do': 3, 'doing': 2, \"don't\": 2, 'drinking': 1, 'driver': 1, 'eat': 1, 'every': 6, 'falling': 3, 'family': 1, 'fast': 1, 'fill': 2, 'find': 1, 'first': 1, 'follow': 6, 'for': 3, 'friends': 1, 'get': 1, 'girl': 2, 'give': 1, 'go': 2, 'going': 1, 'grab': 2, 'hand': 1, 'handmade': 2, 'heart': 3, 'hours': 2, 'how': 1, 'i': 6, \"i'll\": 1, \"i'm\": 23, 'in': 27, 'is': 5, \"isn't\": 1, 'it': 1, 'jukebox': 1, 'just': 1, 'kiss': 1, 'know': 2, 'last': 3, 'lead': 6, 'leave': 1, 'let': 1, \"let's\": 2, 'like': 10, 'love': 25, 'lover': 1, 'magnet': 3, 'make': 1, 'man': 1, 'may': 2, 'me': 10, 'mind': 2, 'much': 2, 'my': 33, 'new': 6, 'night': 3, 'not': 2, 'now': 11, 'of': 6, 'okay': 1, 'on': 40, 'one': 1, 'our': 1, 'out': 1, 'over': 1, 'place': 1, 'plate': 1, 'play': 1, 'pull': 3, 'push': 3, 'put': 3, 'radio': 1, 'room': 3, 'say': 2, 'shape': 6, 'shots': 1, 'singing': 2, 'slow': 1, 'smell': 3, 'so': 2, 'somebody': 2, 'something': 6, 'sour': 1, 'start': 2, 'stop': 1, 'story': 1, 'sweet': 1, 'table': 1, 'take': 1, 'talk': 4, 'taxi': 1, 'tell': 1, 'that': 2, 'the': 18, 'then': 3, 'thrifty': 1, 'to': 2, 'too': 5, 'trust': 1, 'up': 3, 'van': 1, 'waist': 2, 'want': 2, 'was': 2, 'we': 7, \"we're\": 1, 'week': 1, 'were': 3, 'where': 1, 'with': 22, 'you': 16, 'your': 21}\n" + ] + } + ], "source": [ - "# Your code here" + "list_keys= [] #lista de claves del diccionario\n", + "\n", + "for i in word_freq:\n", + " list_keys.append(i)\n", + "\n", + "list_keys.sort() \n", + "print(list_keys)\n", + "\n", + "word_freq2 = {} #llenado de nuevo diccionario\n", + "\n", + "for elemento in list_keys:\n", + " word_freq2[elemento] = word_freq[elemento]\n", + "\n", + "print(word_freq2)" ] }, { @@ -594,15 +1000,41 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[('conversation', 1), (\"we're\", 1), ('plate', 1), ('sour', 1), ('jukebox', 1), ('taxi', 1), ('fast', 1), ('bag', 1), ('man', 1), ('going', 1), ('one', 1), ('backseat', 1), ('friends', 1), ('take', 1), ('play', 1), ('okay', 1), ('begin', 1), ('over', 1), ('just', 1), ('are', 1), ('tell', 1), ('drinking', 1), ('our', 1), ('where', 1), (\"i'll\", 1), ('all', 1), (\"isn't\", 1), ('make', 1), ('lover', 1), ('get', 1), ('radio', 1), ('give', 1), ('can', 1), ('club', 1), ('it', 1), ('out', 1), ('chance', 1), ('first', 1), ('table', 1), ('thrifty', 1), ('driver', 1), ('slow', 1), ('dance', 1), ('trust', 1), ('family', 1), ('week', 1), ('date', 1), ('leave', 1), ('at', 1), ('hand', 1), ('how', 1), ('eat', 1), ('about', 1), ('story', 1), ('sweet', 1), ('best', 1), ('let', 1), ('van', 1), ('shots', 1), ('place', 1), ('find', 1), ('kiss', 1), ('stop', 1), ('bar', 1), (\"don't\", 2), ('mind', 2), ('know', 2), ('so', 2), ('start', 2), ('boy', 2), ('girl', 2), ('singing', 2), ('doing', 2), ('somebody', 2), ('handmade', 2), ('may', 2), ('that', 2), ('much', 2), ('grab', 2), ('was', 2), ('say', 2), ('waist', 2), ('want', 2), (\"let's\", 2), ('not', 2), ('crazy', 2), ('go', 2), ('to', 2), ('fill', 2), ('hours', 2), ('push', 3), ('then', 3), ('put', 3), ('room', 3), ('magnet', 3), ('up', 3), ('pull', 3), ('last', 3), ('do', 3), ('smell', 3), ('although', 3), ('falling', 3), ('were', 3), ('night', 3), ('heart', 3), ('for', 3), ('bedsheets', 3), ('talk', 4), ('too', 5), ('is', 5), ('every', 6), ('new', 6), ('follow', 6), ('brand', 6), ('of', 6), ('i', 6), ('day', 6), ('lead', 6), ('shape', 6), ('discovering', 6), ('something', 6), ('we', 7), ('a', 8), ('like', 10), ('me', 10), ('now', 11), ('baby', 14), ('you', 16), ('be', 16), ('body', 17), ('the', 18), ('your', 21), ('with', 22), (\"i'm\", 23), ('and', 23), ('love', 25), ('in', 27), ('my', 33), ('come', 37), ('on', 40)]\n", + "{'conversation': 1, \"we're\": 1, 'plate': 1, 'sour': 1, 'jukebox': 1, 'taxi': 1, 'fast': 1, 'bag': 1, 'man': 1, 'going': 1, 'one': 1, 'backseat': 1, 'friends': 1, 'take': 1, 'play': 1, 'okay': 1, 'begin': 1, 'over': 1, 'just': 1, 'are': 1, 'tell': 1, 'drinking': 1, 'our': 1, 'where': 1, \"i'll\": 1, 'all': 1, \"isn't\": 1, 'make': 1, 'lover': 1, 'get': 1, 'radio': 1, 'give': 1, 'can': 1, 'club': 1, 'it': 1, 'out': 1, 'chance': 1, 'first': 1, 'table': 1, 'thrifty': 1, 'driver': 1, 'slow': 1, 'dance': 1, 'trust': 1, 'family': 1, 'week': 1, 'date': 1, 'leave': 1, 'at': 1, 'hand': 1, 'how': 1, 'eat': 1, 'about': 1, 'story': 1, 'sweet': 1, 'best': 1, 'let': 1, 'van': 1, 'shots': 1, 'place': 1, 'find': 1, 'kiss': 1, 'stop': 1, 'bar': 1, \"don't\": 2, 'mind': 2, 'know': 2, 'so': 2, 'start': 2, 'boy': 2, 'girl': 2, 'singing': 2, 'doing': 2, 'somebody': 2, 'handmade': 2, 'may': 2, 'that': 2, 'much': 2, 'grab': 2, 'was': 2, 'say': 2, 'waist': 2, 'want': 2, \"let's\": 2, 'not': 2, 'crazy': 2, 'go': 2, 'to': 2, 'fill': 2, 'hours': 2, 'push': 3, 'then': 3, 'put': 3, 'room': 3, 'magnet': 3, 'up': 3, 'pull': 3, 'last': 3, 'do': 3, 'smell': 3, 'although': 3, 'falling': 3, 'were': 3, 'night': 3, 'heart': 3, 'for': 3, 'bedsheets': 3, 'talk': 4, 'too': 5, 'is': 5, 'every': 6, 'new': 6, 'follow': 6, 'brand': 6, 'of': 6, 'i': 6, 'day': 6, 'lead': 6, 'shape': 6, 'discovering': 6, 'something': 6, 'we': 7, 'a': 8, 'like': 10, 'me': 10, 'now': 11, 'baby': 14, 'you': 16, 'be': 16, 'body': 17, 'the': 18, 'your': 21, 'with': 22, \"i'm\": 23, 'and': 23, 'love': 25, 'in': 27, 'my': 33, 'come': 37, 'on': 40}\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "import operator\n", + "sorted_tups = sorted(word_freq.items(), key = operator.itemgetter(1))\n", + "print(sorted_tups)\n", + "\n", + "word_freq3={} #diccionario por llenar\n", + "\n", + "for elemento, valor in sorted_tups: #llenamos el diccionario\n", + " word_freq3[elemento] = valor\n", + "print(word_freq3)\n", + " " ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -616,14 +1048,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" - }, - "vscode": { - "interpreter": { - "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" - } + "version": "3.13.5" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 }