diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..58a9822 Binary files /dev/null and b/.DS_Store differ diff --git a/your-code/challenges.ipynb b/your-code/challenges.ipynb index ba91b3f..66c9e51 100644 --- a/your-code/challenges.ipynb +++ b/your-code/challenges.ipynb @@ -13,11 +13,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I',)\n" + ] + } + ], "source": [ - "# Your code here" + "tup = ('I',)\n", + "print(tup)\n" ] }, { @@ -35,7 +44,7 @@ "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "type(tup)" ] }, { @@ -54,15 +63,20 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "scrolled": true - }, - "outputs": [], + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here\n", - "\n", - "# Your explanation here\n", - "# You can :) " + "# I couldnt use the function append as tupples doesnt work with append \n", + "tup = tup + ('r', 'o', 'n', 'h', 'a', 'c', 'k',)\n", + "print(tup)" ] }, { @@ -84,7 +98,8 @@ "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\",)\n", + "# yes i was able to do it, I cannot change the value of a tupple variable, but i can re-assign the value of the variable.\n" ] }, { @@ -102,11 +117,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n')\n", + "('h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here" + "tup1 = tup[:4]\n", + "tup2 = tup[4:]\n", + "print(tup1)\n", + "print(tup2)" ] }, { @@ -120,11 +147,31 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here" + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tup3 = tup1 + tup2\n", + "print(tup3)\n", + "tup3 == tup" ] }, { @@ -136,11 +183,49 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 53, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n", + "4\n", + "8\n" + ] + } + ], "source": [ - "# Your code here" + "count1 = len(tup1)\n", + "print(count1)\n", + "count2 = len(tup2)\n", + "print(count2)\n", + "total_count = count1 + count2\n", + "print(total_count)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8\n", + "total matches tup3\n" + ] + } + ], + "source": [ + "count3 = len(tup3)\n", + "print(count3)\n", + "if total_count == count3:\n", + " print(\"total matches tup3\")\n", + "else:\n", + " print(\"the total count does not match tup3\")" ] }, { @@ -152,11 +237,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 61, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n" + ] + } + ], "source": [ - "# Your code here" + "print(tup3.index(\"h\"))" ] }, { @@ -176,11 +269,29 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 64, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "a is in tup3\n", + "b it is NOT on tup3\n", + "c is in tup3\n", + "d it is NOT on tup3\n", + "e it is NOT on tup3\n" + ] + } + ], "source": [ - "# Your code here" + "letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n", + "\n", + "for letter in letters:\n", + " if letter in tup3:\n", + " print(f\"{letter} is in tup3\")\n", + " else:\n", + " print(f\"{letter} it is NOT on tup3\")" ] }, { @@ -188,9 +299,7 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "# Your code here" - ] + "source": [] }, { "cell_type": "markdown", @@ -203,11 +312,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 65, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "a appears 1 times in tup3\n", + "b appears 0 times in tup3\n", + "c appears 1 times in tup3\n", + "d appears 0 times in tup3\n", + "e appears 0 times in tup3\n" + ] + } + ], "source": [ - "# Your code here" + "for letter in letters:\n", + " count = tup3.count(letter)\n", + " print(f\"{letter} appears {count} times in tup3\")" ] }, { @@ -223,7 +346,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -248,11 +371,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[75, 86, 51, 30, 83, 28, 23, 3, 99, 88, 76, 48, 45, 31, 50, 57, 95, 81, 60, 14, 100, 78, 26, 17, 11, 12, 69, 59, 50, 96, 99, 10, 58, 46, 68, 23, 51, 12, 73, 96, 93, 70, 98, 98, 30, 100, 23, 94, 5, 18, 8, 47, 75, 89, 21, 75, 88, 63, 79, 45, 7, 8, 81, 81, 18, 40, 85, 9, 33, 43, 17, 91, 89, 39, 42, 59, 95, 100, 17, 41]\n" + ] + } + ], "source": [ - "# Your code here" + "sample_list_1 = [random.randint(1, 100) for _ in range(80)]\n", + "print(sample_list_1)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "80\n" + ] + } + ], + "source": [ + "print(len(sample_list_1))" ] }, { @@ -264,11 +414,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "56" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set1=set(sample_list_1)\n", + "len(set1)\n", + "# when converting to set we have delete duplicated values, thats why now my set is only 54 values\n" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{5, 7, 8, 9, 10, 11, 12, 14, 17, 18, 21, 23, 26, 28, 30, 31, 33, 39, 40, 41, 42, 43, 45, 46, 47, 48, 50, 51, 57, 58, 59, 60, 63, 68, 69, 70, 73, 75, 76, 78, 79, 81, 83, 85, 86, 88, 89, 91, 93, 94, 95, 96, 98, 99, 100}\n" + ] + } + ], "source": [ - "# your code here" + "print(set1)" ] }, { @@ -287,11 +467,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[63, 18, 62, 41, 81, 91, 43, 60, 83, 23, 76, 94, 79, 57, 94, 14, 2, 24, 5, 11, 59, 86, 59, 32, 28, 61, 22, 62, 7, 28, 85, 78, 4, 95, 72, 23, 11, 30, 32, 45, 79, 1, 32, 97, 81, 57, 34, 26, 100, 10, 91, 1, 26, 58, 100, 6, 0, 28, 26, 34, 17, 77, 84, 58, 5, 1, 62, 71, 77, 1, 82, 25, 78, 36, 43, 30, 77, 7, 23, 86]\n" + ] + } + ], "source": [ - "# your code here" + "sample_list_2 = []\n", + "\n", + "for i in range(80):\n", + " value = random.randint(0, 100) \n", + " # generates a random integer between 0 and 100\n", + " sample_list_2.append(value)\n", + "\n", + "print(sample_list_2)\n" ] }, { @@ -303,11 +498,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "49\n" + ] + } + ], "source": [ - "# Your code here" + "set2 = set(sample_list_2)\n", + "print(len(set2))" ] }, { @@ -319,11 +523,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{3, 8, 9, 12, 21, 31, 33, 39, 40, 42, 46, 47, 48, 50, 51, 68, 69, 70, 73, 75, 88, 89, 93, 96, 98, 99}\n" + ] + } + ], "source": [ - "# Your code here" + "set3 = set1 - set2\n", + "print(set3)" ] }, { @@ -335,11 +548,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 1, 2, 4, 6, 22, 24, 25, 32, 34, 36, 61, 62, 71, 72, 77, 82, 84, 97}\n" + ] + } + ], "source": [ - "# Your code here" + "set4 = set2 - set1\n", + "print(set4)" ] }, { @@ -351,11 +573,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{5, 7, 10, 11, 14, 17, 18, 23, 26, 28, 30, 41, 43, 45, 57, 58, 59, 60, 63, 76, 78, 79, 81, 83, 85, 86, 91, 94, 95, 100}\n" + ] + } + ], "source": [ - "# Your code here" + "set5 = set1 & set2\n", + "print(set5)" ] }, { @@ -377,9 +608,34 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], "source": [ - "# Your code here" + "print(len(set1) == len(set3) + len(set5)) \n" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "print(len(set2) == len(set4) + len(set5)) " ] }, { @@ -391,11 +647,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "set" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "set6=set()\n", + "type(set6)" ] }, { @@ -407,11 +675,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{3, 5, 7, 8, 9, 10, 11, 12, 14, 17, 18, 21, 23, 26, 28, 30, 31, 33, 39, 40, 41, 42, 43, 45, 46, 47, 48, 50, 51, 57, 58, 59, 60, 63, 68, 69, 70, 73, 75, 76, 78, 79, 81, 83, 85, 86, 88, 89, 91, 93, 94, 95, 96, 98, 99, 100}\n", + "Length of set6: 56\n" + ] + } + ], "source": [ - "# Your code here" + "# Then, use the update() method to add all elements from set3 and set5\n", + "set6.update(set3, set5)\n", + "\n", + "# Optional: print the result to verify\n", + "print(set6)\n", + "print(\"Length of set6:\", len(set6))\n" ] }, { @@ -423,11 +705,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Set1 is equal to set6\n" + ] + } + ], "source": [ - "# Your code here" + "if set1 == set6:\n", + " print(\"Set1 is equal to set6\")" ] }, { @@ -439,11 +730,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "set1 does NOT contain all elements of set2\n" + ] + } + ], "source": [ - "# Your code here" + "if set1.issuperset(set2):\n", + " print(\"set1 contains all elements of set2\")\n", + "else:\n", + " print(\"set1 does NOT contain all elements of set2\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "set1 contains all elements of set3\n" + ] + } + ], + "source": [ + "if set1.issuperset(set3):\n", + " print(\"set1 contains all elements of set3\")\n", + "else:\n", + " print(\"set1 does NOT contain all elements of set3\")\n" ] }, { @@ -457,11 +779,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "agg1 = set3.union(set4, set5)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [], + "source": [ + "agg2 = set1.union(set2)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The sets3, 4 and 5 sum is equal to Set1 and 2 sum.\n" + ] + } + ], + "source": [ + "if agg1 == agg2:\n", + " print(\"The sets3, 4 and 5 sum is equal to Set1 and 2 sum.\")\n", + "else:\n", + " print(\"The aggregated sets are NOT equal.\")\n" ] }, { @@ -473,11 +824,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 41, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Removed element: 3\n", + "Updated set1: {5, 7, 8, 9, 10, 11, 12, 14, 17, 18, 21, 23, 26, 28, 30, 31, 33, 39, 40, 41, 42, 43, 45, 46, 47, 48, 50, 51, 57, 58, 59, 60, 63, 68, 69, 70, 73, 75, 76, 78, 79, 81, 83, 85, 86, 88, 89, 91, 93, 94, 95, 96, 98, 99, 100}\n" + ] + } + ], "source": [ - "# Your code here" + "removed_element = set1.pop()\n", + "print(\"Removed element:\", removed_element)\n", + "print(\"Updated set1:\", set1)" ] }, { @@ -493,11 +855,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Remaining elements in set1: {5, 7, 8, 10, 12, 14, 17, 18, 23, 26, 28, 30, 33, 40, 42, 43, 45, 46, 47, 48, 50, 57, 58, 60, 63, 68, 70, 73, 75, 76, 78, 83, 85, 86, 88, 93, 94, 95, 96, 98, 100}\n" + ] + } + ], "source": [ - "# Your code here" + "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 value in list_to_remove:\n", + " set1.discard(value)\n", + "print(\"Remaining elements in set1:\", set1)\n" ] }, { @@ -515,7 +888,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, "outputs": [], "source": [ @@ -551,7 +924,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "metadata": {}, "outputs": [], "source": [ @@ -592,7 +965,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": {}, "outputs": [], "source": [ @@ -602,7 +975,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -616,12 +989,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" - }, - "vscode": { - "interpreter": { - "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" - } + "version": "3.13.7" } }, "nbformat": 4,