diff --git a/your-code/challenges.ipynb b/your-code/challenges.ipynb index ba91b3f..ea2d469 100644 --- a/your-code/challenges.ipynb +++ b/your-code/challenges.ipynb @@ -15,9 +15,17 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ - "# Your code here" + "tup = tuple(\"I\")" ] }, { @@ -31,11 +39,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ - "# Your code here" + "print(type(tup))" ] }, { @@ -59,10 +75,9 @@ }, "outputs": [], "source": [ - "# Your code here\n", - "\n", - "# Your explanation here\n", - "# You can :) " + " You can't append items to a tuple because tuples are immutable, so when a tuple is created, it must stay that way\n", + " \n", + " " ] }, { @@ -80,11 +95,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")" ] }, { @@ -102,11 +117,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n') ('h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here" + "tup1 = (\"I\", \"r\", \"o\", \"n\")\n", + "tup2 = (\"h\", \"a\", \"c\", \"k\")\n", + "print(tup1, tup2)" ] }, { @@ -120,11 +145,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here" + "tup3 = tup1 + tup2\n", + "print(tup3)" ] }, { @@ -136,11 +170,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8\n", + "8\n" + ] + } + ], "source": [ - "# Your code here" + "print(len(tup1) + len(tup2))\n", + "print(len(tup3))" ] }, { @@ -152,11 +196,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n" + ] + } + ], "source": [ - "# Your code here" + "print(tup3.index(\"h\"))" ] }, { @@ -176,11 +228,29 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "True\n", + "False\n", + "False\n" + ] + } + ], "source": [ - "# Your code here" + "letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n", + "\n", + "for letter in letters:\n", + " if letter in tup3:\n", + " print(\"True\")\n", + " else:\n", + " print(\"False\")" ] }, { @@ -203,11 +273,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "a: 1\n", + "b: 0\n", + "c: 1\n", + "d: 0\n", + "e: 0\n" + ] + } + ], "source": [ - "# Your code here" + "\n", + "for letter in letters:\n", + " print(f\"{letter}: {tup3.count(letter)}\")\n", + "\n", + " " ] }, { @@ -223,7 +309,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -248,11 +334,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[72, 10, 11, 19, 37, 65, 87, 42, 32, 95, 59, 89, 47, 98, 31, 50, 52, 77, 67, 35, 96, 14, 48, 38, 18, 44, 21, 4, 13, 66, 91, 79, 28, 71, 25, 55, 20, 22, 99, 24, 94, 6, 2, 84, 56, 46, 93, 34, 88, 29, 81, 43, 54, 8, 82, 36, 49, 73, 51, 76, 12, 64, 1, 97, 92, 40, 41, 62, 17, 100, 15, 86, 63, 83, 74, 68, 26, 9, 0, 53]\n", + "80\n" + ] + } + ], "source": [ - "# Your code here" + "sample_list_1 = random.sample(range(0, 101), 80)\n", + "print(sample_list_1)\n", + "print(len(sample_list_1))" ] }, { @@ -266,9 +363,20 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 1, 2, 4, 6, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 24, 25, 26, 28, 29, 31, 32, 34, 35, 36, 37, 38, 40, 41, 42, 43, 44, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 59, 62, 63, 64, 65, 66, 67, 68, 71, 72, 73, 74, 76, 77, 79, 81, 82, 83, 84, 86, 87, 88, 89, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100}\n" + ] + } + ], "source": [ - "# your code here" + "set1 = set(sample_list_1)\n", + "print(set1)\n", + "\n", + "the set now is 100 values" ] }, { @@ -287,11 +395,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[96, 64, 64, 25, 65, 50, 98, 55, 59, 89, 69, 14, 10, 96, 54, 97, 86, 89, 21, 4, 90, 91, 91, 83, 51, 1, 0, 48, 22, 58, 32, 3, 13, 83, 28, 9, 63, 86, 71, 88, 30, 47, 93, 83, 7, 41, 3, 24, 51, 30, 30, 79, 6, 44, 42, 37, 52, 67, 83, 70, 84, 12, 33, 76, 4, 40, 32, 56, 28, 1, 13, 48, 76, 39, 9, 16, 28, 44, 52, 95]\n", + "80\n" + ] + } + ], "source": [ - "# your code here" + "sample_list_2 = []\n", + "for value in range(80):\n", + " sample_list_2.append(random.randint(0, 100))\n", + "print(sample_list_2)\n", + "print(len(sample_list_2))" ] }, { @@ -303,11 +424,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "57\n" + ] + } + ], "source": [ - "# Your code here" + "set2 = set(sample_list_2)\n", + "print(len(set2))" ] }, { @@ -319,11 +449,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "set3 = set1 - set2" ] }, { @@ -335,11 +465,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "set4 = set2 - set1" ] }, { @@ -351,11 +481,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "set5 = set1 | set2" ] }, { @@ -375,11 +505,34 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here" + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "80\n", + "57\n", + "31\n", + "8\n", + "88\n", + "len(set3) + len(set4) + len(set1 & set2): 88\n", + "len(set5): 88\n", + "Are they equal? True\n" + ] + } + ], + "source": [ + "print(len(set1))\n", + "print(len(set2))\n", + "print(len(set3))\n", + "print(len(set4))\n", + "print(len(set5))\n", + "\n", + "print(\"len(set3) + len(set4) + len(set1 & set2):\", len(set3) + len(set4) + len(set1 & set2))\n", + "print(\"len(set5):\", len(set5))\n", + "print(\"Are they equal?\", (len(set3) + len(set4) + len(set1 & set2)) == len(set5))" ] }, { @@ -391,11 +544,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "set6 = set()\n" ] }, { @@ -407,11 +560,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 44, 47, 48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 59, 60, 62, 63, 64, 65, 67, 68, 69, 70, 71, 72, 74, 76, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 100}\n" + ] + } + ], "source": [ - "# Your code here" + "set6.update(set3)\n", + "set6.update(set5)\n", + "print(set6)" ] }, { @@ -423,11 +586,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 132, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n" + ] + } + ], "source": [ - "# Your code here" + "print(set1 == set6)" ] }, { @@ -439,11 +610,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "False\n" + ] + } + ], "source": [ - "# Your code here" + "print(set1.issubset(set2))\n", + "print(set1.issubset(set3))" ] }, { @@ -457,11 +638,110 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here" + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{0,\n", + " 1,\n", + " 2,\n", + " 3,\n", + " 4,\n", + " 6,\n", + " 7,\n", + " 8,\n", + " 9,\n", + " 10,\n", + " 11,\n", + " 12,\n", + " 13,\n", + " 14,\n", + " 15,\n", + " 16,\n", + " 17,\n", + " 18,\n", + " 19,\n", + " 20,\n", + " 21,\n", + " 22,\n", + " 23,\n", + " 24,\n", + " 25,\n", + " 26,\n", + " 28,\n", + " 29,\n", + " 30,\n", + " 31,\n", + " 32,\n", + " 33,\n", + " 34,\n", + " 35,\n", + " 36,\n", + " 37,\n", + " 38,\n", + " 39,\n", + " 40,\n", + " 41,\n", + " 42,\n", + " 44,\n", + " 47,\n", + " 48,\n", + " 49,\n", + " 50,\n", + " 51,\n", + " 52,\n", + " 54,\n", + " 55,\n", + " 56,\n", + " 57,\n", + " 58,\n", + " 59,\n", + " 60,\n", + " 62,\n", + " 63,\n", + " 64,\n", + " 65,\n", + " 67,\n", + " 68,\n", + " 69,\n", + " 70,\n", + " 71,\n", + " 72,\n", + " 74,\n", + " 76,\n", + " 78,\n", + " 79,\n", + " 80,\n", + " 81,\n", + " 82,\n", + " 83,\n", + " 84,\n", + " 85,\n", + " 86,\n", + " 88,\n", + " 89,\n", + " 90,\n", + " 91,\n", + " 92,\n", + " 93,\n", + " 94,\n", + " 95,\n", + " 96,\n", + " 97,\n", + " 98,\n", + " 100}" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set6.union(set3 and set4 and set5)\n", + "set6.union(set1 and set2)" ] }, { @@ -473,11 +753,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 133, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 133, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "set1.pop()" ] }, { @@ -493,11 +784,25 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 134, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{2, 4, 6, 8, 10, 12, 13, 14, 15, 17, 18, 20, 22, 24, 25, 26, 28, 32, 34, 35, 36, 37, 38, 40, 42, 43, 44, 46, 47, 48, 50, 52, 53, 54, 55, 56, 62, 63, 64, 65, 66, 67, 68, 72, 73, 74, 76, 77, 82, 83, 84, 86, 87, 88, 92, 93, 94, 95, 96, 97, 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", + "\n", + "for number in list_to_remove:\n", + " if number in set1:\n", + " set1.remove(number)\n", + " \n", + "print(set1)" ] }, { @@ -515,7 +820,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 135, "metadata": {}, "outputs": [], "source": [ @@ -551,11 +856,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 147, "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" + "keys = list(word_freq.keys())\n", + "keys.sort()\n", + "print(keys)\n", + "\n", + "word_freq2 = {}\n", + "\n", + "for key in keys:\n", + " word_freq2[key] = word_freq[key]\n", + "\n", + "print(word_freq2)" ] }, { @@ -590,19 +913,56 @@ "```" ] }, + { + "cell_type": "code", + "execution_count": 153, + "metadata": {}, + "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" + ] + } + ], + "source": [ + "import operator\n", + "sorted_tups = sorted(word_freq.items(), key=operator.itemgetter(1))\n", + "\n", + "word_freq2 = {}\n", + "\n", + "for key, value in sorted_tups:\n", + " word_freq2[key] = value\n", + "\n", + "print(word_freq2)\n" + ] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "# Your code here" - ] + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -616,12 +976,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" - }, - "vscode": { - "interpreter": { - "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" - } + "version": "3.13.5" } }, "nbformat": 4,